Skip to content

edit-package-json incompatibility with typescript 4.7.3, moduleResolution Node16 #47

Description

@paulzacz

Package's name
Which package from the monorepo is it for?

edit-package-json

Describe the bug
A clear and concise description of what the bug is.

Typescript cannot find the types for edit-package-json when using "moduleResolution": "Node16", on typescript v4.7.3

To Reproduce
Steps to reproduce the behavior:

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "Node16",
  }
}

Sample file:

import { del, set } from 'edit-package-json';

Error message:

error TS7016: Could not find a declaration file for module 'edit-package-json'. 'node_modules/edit-package-json/dist/edit-package-json.esm.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/edit-package-json` if it exists or add a new declaration (.d.ts) file containing `declare module 'edit-package-json';`

import { del, set } from 'edit-package-json';

Expected behavior
Typescript is able to find the type definitions.

Additional context
Typescript 4.7.3 added support for ESM modules in node.js, including the "exports" keyword in package.json. The relevant portion of package.json for edit-package-json is as follows:

  "exports": {
    "script": "./dist/edit-package-json.umd.js",
    "default": "./dist/edit-package-json.esm.js"
  },
  "types": "types/index.d.ts",

As written, Typescript 4.7.3 is looking for ./dist/edit-package-json.esm.d.ts, but that files does not exist. Either add a "types" within the "exports" section pointing to the right file, or change the build process to output a definition file in the expected location with the expected name. Typescript 4.7.3 exports reference

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions