Property db doesn't exist on XataClient

With the code
import { getXataClient } from "../../xata";
const xata = getXataClient();
console.log(xata)
// returns
// XataClient {
// db: {},
// search: { all: [AsyncFunction: all], byTable: [AsyncFunction: byTable] },
// transactions: { run: [AsyncFunction: run] }
}
import { getXataClient } from "../../xata";
const xata = getXataClient();
console.log(xata)
// returns
// XataClient {
// db: {},
// search: { all: [AsyncFunction: all], byTable: [AsyncFunction: byTable] },
// transactions: { run: [AsyncFunction: run] }
}
But when I try
console.log(xata.db);
console.log(xata.db);
I get the error: Property 'db' does not exist on type 'XataClient'
13 Replies
PeanutDumplings
This is because when I made an initial query to create some data It returned the same error
kostas
kostas2y ago
Hello! Can you confirm if the path ../../xata is the location of xata.ts (which defaults to src/xata.ts from the place where you do xata init) ? Just to provide an overview, when you run the CLI command xata init which configures your current directory, that downloads the xata client module in node_modules and at the same time generates a file in the location src/xata.ts which contains your types, db details etc. This is the place you should get the xata client from, so we need to make sure that file corresponds to the path we're importing. This file extends the xata client node module with your own database specifics / types. As a sidenote, if you make changes in the UI, for example create new tables or change the schema of an existing table, you would need to run xata codegen to update your client file with the latest changes.
PeanutDumplings
The path ../../xata is correct and finds the src/xata.ts file. I've ran xata codegen again, which updated the tables array (with the new table that I created), but still I get the same errors I even ran xata init --force to re-init the project, which yet again didn't work
kostas
kostas2y ago
I see. Which framework are you using? How are you running this ts code? (And it's on Windows right?)
PeanutDumplings
I'm just using plain ts, and using nodemon currently to run the native typescript code (as it wont compile with that issue), and it is windows
kostas
kostas2y ago
Then it must have to do with the compiler configuration. Your code above works for me using nodemon 2.0.22 and tsc 4.7.4 (the Xata client is compatible with typescript 4.7+, just noting) with the defaults (no tsconfig file) but I was able to get the Property 'db' does not exist on type 'XataClient' using some module/target combinations. Can you paste your tsconfig.json?
PeanutDumplings
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"target": "ES6",
"outDir": "./dist",
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"target": "ES6",
"outDir": "./dist",
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}
kostas
kostas2y ago
Thank you, we will take a look with the dev team for suggestions. To confirm, which version of typescript are you using?
PeanutDumplings
5.0.4
kostas
kostas2y ago
Can you try "moduleResolution": "node" to see if it fixes the issue ? The dev team identified an issue with the types export that may be impacting some libraries. We are working on it and will release an updated client version soon. I will let you know to try it out once it's available. In the meantime you can try setting module resolution to node to see if it helps.
PeanutDumplings
Thanks, that worked. Any update on this?
kostas
kostas2y ago
@PeanutDumplings The dev team has an improvement for the client which should fix the issue with NodeNext module resolution. It will be available with the upcoming release later this week, most likely around Wednesday!
PeanutDumplings
Thanks :hapi:
Want results from more Discord servers?
Add your server