Skip to content

fix: resolve lodash functions via named entry points, not named imports - #271

Merged
cdmren merged 1 commit into
mainfrom
cdm/fix-lodash-named-imports
Aug 25, 2026
Merged

fix: resolve lodash functions via named entry points, not named imports#271
cdmren merged 1 commit into
mainfrom
cdm/fix-lodash-named-imports

Conversation

@cdmren

@cdmren cdmren commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #270

src/index.ts, src/formatting.ts, and src/path.ts imported functions from lodash with named imports (e.g. import {reduce, map as _map, find} from 'lodash'). lodash is CommonJS and has no static named exports, so this breaks under any consumer that resolves it through native ESM — e.g. Vitest — now that this package declares "type": "module". Bundler-based tooling (Vite, esbuild) and tsc under looser moduleResolution settings tolerate the interop, which is why this only surfaced in downstream test suites, not builds or typechecks.

Switched each import to its own entry point instead (import reduce from 'lodash/reduce.js'), with an explicit .js extension — required for this repo's own tsc build under moduleResolution: NodeNext, which needs fully-specified ESM specifiers. src/index.test.ts and src/test-helper.ts had the same pattern (forEach, identity) and got the same fix, since they'd hit the same failure if this package's own test suite were consumed the same way.

Verified locally: pnpm build and pnpm test (76/76) pass here, and — more importantly — linking this branch into freckle/megarepo's frontend/platform/console (which was failing exactly this way after bumping to @freckle/parser@3.0.0) and running its full Vitest suite now passes 570/570, where it previously failed with the SyntaxError: Named export 'map' not found error described in #270.

dist/ is rebuilt and committed alongside src/, per this repo's own check-git-clean.sh convention.

  • Claude

lodash is CommonJS with no static named exports, so `import {map} from
'lodash'` breaks under any consumer resolving it through native ESM
(e.g. Vitest), now that this package declares "type": "module". Import
each function from its own entry point instead.
@github-actions

Copy link
Copy Markdown

PR checklist

  • Version in package.json is updated according to semver policy.
  • Built dist/ reflects all changes in PR prior to merge.

@cdmren
cdmren marked this pull request as ready for review August 24, 2026 20:51
@cdmren
cdmren requested a review from a team as a code owner August 24, 2026 20:51
@cdmren
cdmren requested review from jleichty-ren and removed request for a team August 24, 2026 20:51
@cdmren
cdmren enabled auto-merge August 24, 2026 21:05
@cdmren
cdmren requested a review from joris974 August 25, 2026 15:20

@joris974 joris974 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. I am pretty sure we can remove lodash and use native JS functions for many of the usecase here (map, find, reduce, forEach). identity is an interesting one I haven't used before

@cdmren
cdmren merged commit 9921b7e into main Aug 25, 2026
6 checks passed
@cdmren
cdmren deleted the cdm/fix-lodash-named-imports branch August 25, 2026 15:38
@joris974 joris974 mentioned this pull request Aug 25, 2026
4 tasks
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.

v3.0.0: named imports from lodash break under Vitest's native ESM resolution

2 participants