pgtyped
pgtyped copied to clipboard
wrong module resolution when using typescript from commonjs
Describe the bug trying to use the latest version of pgtyped from a commonjs project causes typescript to complain with
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@pgtyped/runtime")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to 'XXXX/package.json'.
this is caused by a wrong exports
declaration in your package.json.
see here and here for details
Expected behavior typescript does not fail
Test case
npm i -D @tsconfig/node20
tsconfig.json:
{
"extends": "@tsconfig/node20",
}
src/index.ts
import { PreparedQuery } from '@pgtyped/runtime';