Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Types do not resolve properly in an ESM TypeScript project #522

Closed
sam-goodwin opened this issue May 20, 2023 · 2 comments
Closed
Labels
🐛 bug Something isn't working untriaged

Comments

@sam-goodwin
Copy link

What is the bug?

The type declarations do not work when using ESM. I am getting the following error

Could not find a declaration file for module '@opensearch-project/opensearch'. '/Users/samgoodwin/workspaces/eventual-live/node_modules/.pnpm/@opensearch-project+opensearch@1.2.0/node_modules/@opensearch-project/opensearch/index.mjs' implicitly has an 'any' type.
  There are types at '/Users/samgoodwin/workspaces/eventual-live/packages/@eventual/core/node_modules/@opensearch-project/opensearch/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@opensearch-project/opensearch' library may need to update its package.json or typings.ts(7016)

Looks like there is a bug with the exports configuration for ESM support. This is the most important part:

There are types at /(my-workspace)/packages/@eventual/core/node_modules/@opensearch-project/opensearch/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@opensearch-project/opensearch library may need to update its package.json or typings.

How can one reproduce the bug?

Consume this package from a typescript project with the following tsconfig settings:

"module": "esnext",
"moduleResolution": "NodeNext",

What is the expected behavior?

There should be no error when importing this package in a TypeScript project using ESM.

What is your host/environment?

macOS 13.1 (22C65)

@thantos
Copy link

thantos commented May 20, 2023

Typescript docs say that the "types" export condition should be before all others and that ESM and CJS should have their own .d.(?)ts files.

Current

"exports": {
    ".": {
      "require": "./index.js",
      "types": "./index.d.ts",
      "import": "./index.mjs"
    },
    "./aws": "./lib/aws/index.js",
    "./*": "./*"
  },

Expected

"exports": {
    ".": {
      "require": { 
          "types": "./index.d.ts",
          "default": "./index.js"
      },
      "import": { 
          "types": "./index.d.mts",
          "default": "./index.mjs"
      },
    },
    "./aws": "./lib/aws/index.js",
    "./*": "./*"
  },

@sam-goodwin
Copy link
Author

My issue is caused by the broken latest tag in NPM #521

@wbeckler wbeckler added the 🐛 bug Something isn't working label Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

3 participants