Skip to content

Emit namespace import for lodash in ESM bundle - #720

Open
paulsmirnov wants to merge 1 commit into
mainfrom
715-import-of-lodash-package-as-default-causes-other-packages-eg-turbopack-in-my-case-unable-to-resolve-it
Open

paulsmirnov wants to merge 1 commit into
mainfrom
715-import-of-lodash-package-as-default-causes-other-packages-eg-turbopack-in-my-case-unable-to-resolve-it

Conversation

@paulsmirnov

Copy link
Copy Markdown
Member

Summary

Configure externals.lodash.module as ['lodash', 'default'] in packages/miew/webpack.config.js so Webpack emits a namespace import (import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";) and unwraps .default internally in the ESM bundle (Miew.module.js).

This restores backwards compatibility with the v0.11.1 import shape and avoids Next.js/Turbopack's broken modularizeImports rewrite (import { default as ... } from "lodash" → lodash/default), without altering import _ from 'lodash' in source files.

Closes #715

Verification

  • yarn workspace miew run build:js — verified build/dist/Miew.module.js emits import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; with no { default as ... } from "lodash" import.
  • Verified runtime Miew.thirdParty.lodash resolution in Node.js across ESM (Miew.module.js), UMD (Miew.js), and minified UMD (Miew.min.js) bundles.
  • yarn workspace miew ci-fast — ESLint, 642 unit tests, JS/CSS builds, example builds, and JSDoc all passed.
  • yarn workspace miew run lint:js — passed after adding the inline issue reference comment.

Configure externals.lodash.module as ['lodash', 'default'] so Webpack
emits `import * as ... from "lodash"` instead of
`import { default as ... } from "lodash"`, avoiding Next.js/Turbopack's
broken `lodash/default` rewrite.

Closes #715
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 31.628%. remained the same — 715-import-of-lodash-package-as-default-causes-other-packages-eg-turbopack-in-my-case-unable-to-resolve-it into main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import of Lodash package as default causes other packages (e.g. Turbopack in my case) unable to resolve it

2 participants