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

TypeScript issue: moduleResolution:NodeNext doesn’t work with this library #271

Open
rauschma opened this issue Jan 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rauschma
Copy link

rauschma commented Jan 21, 2024

The problem

tsconfig.json:

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

TypeScript code:

import { parse } from '@adobe/css-tools';

Result – error from tsc:

  • Could not find a declaration file for module '@adobe/css-tools'. '~/my-lib/node_modules/@adobe/css-tools/dist/index.mjs' implicitly has an 'any' type.
    • There are types at '~/my-lib/node_modules/@adobe/css-tools/dist/types.d.ts', but this result could not be resolved when respecting package.json "exports". The '@adobe/css-tools' library may need to update its package.json or typings.

Solutions

Quickest fix – change package.json:

"exports": {
  "import": "./dist/index.mjs",
  "types": "./dist/types.d.ts",
  "require": "./dist/index.cjs"
},

In the long run, you don’t need "main", "module" and "types" (anywhere!) anymore, as these are superseded by "exports" and modern TypeScript .d.ts resolution. You only have to rename:

mv types.d.ts index.d.mts

Possibly useful

@rauschma rauschma changed the title TypeScript issue: moduleResolution:NodeNext doesn’t work with this library TypeScript issue: moduleResolution:NodeNext doesn’t work with this library Jan 21, 2024
@holblin
Copy link

holblin commented Jan 25, 2024

Fixed through #274
I will keep this issue open for the long term solution.

Thanks a lot for that detailed issue. This is very use full and well detailed. I truly appreciated.

@holblin holblin added the enhancement New feature or request label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants