Skip to content

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

@rauschma

Description

@rauschma

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions