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
With "type": "module" in the package.json, and and named import of a function from lodash (Pure CJS, not statically analyzable by Node.js). You will get an error:
> start
> tsx index.ts
(node:10) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///home/projects/node-bixnfe/index.ts:1
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:true});import{pad}from"lodash";function sayHello(name){console.log(pad(`Hello ${name}`,80))}__name(sayHello,"sayHello");sayHello("World");
^^^
SyntaxError: The requested module 'lodash' does not provide an export named 'pad'
at ModuleJob._instantiate (https://nodebixnfe-doob.w-credentialless.staticblitz.com/blitz.09144545.js:181:1509)
at async ModuleJob.run (https://nodebixnfe-doob.w-credentialless.staticblitz.com/blitz.09144545.js:181:2327)
Although there is also lodash-es, you still encounter packages importing lodash directly from within them, where replacing them all with lodash-es is difficult and sometimes causes issues, as those are sometimes meant to be consumed from vanilla Node.js CJS mode, which can't require ESM modules. And merging lodash into a proper hybrid package isn't happening anytime soon due to the poor maintenance status of lodash (lodash/lodash#5107).
Problem
With
"type": "module"
in thepackage.json
, and and named import of a function fromlodash
(Pure CJS, not statically analyzable by Node.js). You will get an error:Although there is also
lodash-es
, you still encounter packages importinglodash
directly from within them, where replacing them all withlodash-es
is difficult and sometimes causes issues, as those are sometimes meant to be consumed from vanilla Node.js CJS mode, which can'trequire
ESM modules. And merginglodash
into a proper hybrid package isn't happening anytime soon due to the poor maintenance status of lodash (lodash/lodash#5107).Expected behavior
It just works.
Minimal reproduction URL
https://stackblitz.com/edit/node-bixnfe?file=index.ts
Version
v3.12.1
Node.js version
v18.18.0
Package manager
npm
Operating system
Linux
Contributions
The text was updated successfully, but these errors were encountered: