Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lodash named exports fails to import with "type": "module" in package.json #361

Closed
2 tasks
segevfiner opened this issue Oct 31, 2023 · 5 comments
Closed
2 tasks
Labels
bug Something isn't working outdated pending triage

Comments

@segevfiner
Copy link

Problem

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).

screenshot

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

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@segevfiner segevfiner added bug Something isn't working pending triage labels Oct 31, 2023
@pokey

This comment was marked as off-topic.

@pokey

This comment was marked as off-topic.

@privatenumber

This comment was marked as off-topic.

@pokey

This comment was marked as off-topic.

@privatenumber
Copy link
Owner

Duplicate of #38

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated pending triage
Projects
None yet
Development

No branches or pull requests

3 participants