node-postgres
node-postgres copied to clipboard
Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations.
the file node_modules/@types/pg/index.d.ts make use of an import that does not seem to works.
A valid import is import { NoticeMessage } from 'pg-protocol/dist/messages.js'. Maybe you changed the package.json of pg-protocol and it broke the exports
I think you are referring to https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0eed2e092e4fbcfdef10559bd13f0c3401325010/types/pg/index.d.ts#L6
We need more information.
This works for me:
$ mkdir Code/np-3492
$ npm i typescript @types/pg pg tsx
// file index.ts
import { Client } from 'pg';
async function main() {
const client = new Client({
user: 'user',
host: 'localhost',
database: 'my-db',
password: 'your_password',
port: 5432,
});
try {
await client.connect();
const res = await client.query('SELECT 1;');
console.log(res.rows);
} catch (err) {
console.error('Error executing query', err.stack);
} finally {
await client.end();
}
}
main().catch(err => {
console.error('Error in main function', err);
});
$ npx tsx index.ts
[ { '?column?': 1 } ]