I just tried starting to use pg-promise and ran into an error I cannot understand at all. I am kinda new to typescript in general, so it might be more of a typescript error and not a pg-promise one.
I do have the following code:
import {join} from "path/posix";
import {QueryFile, IQueryFileOptions} from 'pg-promise';
export const users = {
create: sql('users/create.sql'),
all: sql('users/all.sql')
};
function sql(file: string): QueryFile {
const fullPath: string = join(__dirname, file); // generating full path;
const options: IQueryFileOptions = {
minify: true
};
const qf: QueryFile = new QueryFile(fullPath, options);
if (qf.error) {
console.log("TEst")
}
return qf;
}
When I try running it using tsx index.ts I do receive the following error:
The requested module 'pg-promise' does not provide an export named 'QueryFile'
This is weird, because this is kind of the example code given by vitaly. My tsconfig is the following:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"strict": true,
"resolveJsonModule": true
},
"exclude": [
"node_modules"
]
}
Again, its the same as in vitaly's example
When trying to run it using ts-node it also throws an error, which might be a hint for someone more experienced than me to solve my problem?:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/myname/Desktop/web-api/test.ts
Thanks for you help in advance :)
I tried 20+ different tsconfigs because I dont know if this is the root cause for this problem. I tried to run this code on another version of node (20, 18, 16...)