Skip to content

New exports break TypeScript "bundler" compilation #3457

Open
@pfumagalli

Description

@pfumagalli

"exports": {
".": {
"import": "./esm/index.js",
"require": "./dist/index.js",
"default": "./dist/index.js"
},
"./dist/*": {
"import": "./dist/*",
"require": "./dist/*",
"default": "./dist/*"
}
},

It seems that by adding the new "exports" flags to package.json, now when compiling anything depending on pg (and relatively @types/pg) using the bundler module resolution fails with:

│ /home/runner/work/lib-sqs/lib-sqs/node_modules/@types/pg/index.d.ts
│   12:31  Cannot find module 'pg-protocol/dist/messages' or its corresponding type declarations. [TS2307]
│          | import { NoticeMessage } from 'pg-protocol/dist/messages';

I think the correct definition for the dist export in package.json should be something like the following:

"exports": {
  ".": {
    "import": "./esm/index.js",
    "types": "./dist/index.d.ts",
    "require": "./dist/index.js",
    "default": "./dist/index.js"
  },
  "./dist/*": {
    "types": "./dist/*.d.ts",
    "require": "./dist/*.js"
  }
}

Nothing in dist seems to be an ESM module (so no "import") and types and extensions should be explicit...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions