Skip to content

Issue with ESM "exports" at runtime #263

@edouardmercier

Description

@edouardmercier

When using Caporal v3.15.0 under macOS, within an ESM application (written in TypeScript), at runtime the module throws the following exception:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '<path>/electron/node_modules/lodash/kebabCase' imported from <path>/node_modules/@caporal/core/dist/index.mjs

It seems that this is due to the faulty exports JSON root element in the package.json module, which as the value

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

and which seems to cause the resolver to fail. When removing that exports JSON element, the runtime is fine. I'm not very familiar with the syntax of the Node.js import and exports JSON properties, see https://nodejs.org/api/packages.html#subpath-exports, hence I was not able to figure exactly why the removal of the exports element solves the issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions