adobe/css-tools

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

Opened this issue · 1 comments

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

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.