adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

Typescript issues when moduleResolution is `nodeNext` or `node16` #547

Closed tim-field closed 9 months ago

tim-field commented 10 months ago

Describe the bug

I'm working in a project with the following tsconfig

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "compilerOptions": {
    "strict": true,
    "target": "ES2022",
    "module": "node16",
    "moduleResolution": "node16"
  },
  "include": ["src"]
}

When I try to use pgtyped I get the following in the generated files.

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, ...

image

Should this work? or am I doing something wrong?

tim-field commented 9 months ago

Sorry this was user error with my tsconfig esm setup. "type": "module" in package.json was missing