You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a JS project with "type": "module", in the package.json, the following code:
import{cancelable}from'cancelable-promise';
will throw the error:
import { cancelable } from 'cancelable-promise';
^^^^^^^^^^
SyntaxError: Named export 'cancelable' not found. The requested module 'cancelable-promise' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'cancelable-promise';
const { cancelable } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.1
As mentioned in the error, you can do this as a workaround:
However this issue still leads to unexpected failures as the error can only be caught at runtime. Typescript does not catch this error at compile time.
Ultimately, this comes down to how the export is declared in the package.json. You can see the root of the problem here: https://publint.dev/[email protected]
I'll open a PR to fix this.
The text was updated successfully, but these errors were encountered:
In a JS project with
"type": "module",
in the package.json, the following code:will throw the error:
As mentioned in the error, you can do this as a workaround:
However this issue still leads to unexpected failures as the error can only be caught at runtime. Typescript does not catch this error at compile time.
Ultimately, this comes down to how the export is declared in the package.json. You can see the root of the problem here: https://publint.dev/[email protected]
I'll open a PR to fix this.
The text was updated successfully, but these errors were encountered: