Skip to content

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

Description

@cdmren

src/index.ts imports from lodash like this:

import {reduce, map as _map, find} from 'lodash'

lodash is CommonJS and has no static named exports, so this fails under any consumer whose test runner resolves it through native ESM (e.g. Vitest), now that this package itself declares "type": "module":

SyntaxError: Named export 'map' not found. The requested module 'lodash' 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 'lodash';
const { map } = pkg;

src/formatting.ts has the same pattern (import {times} from 'lodash').

This doesn't show up in tsc or in bundler-based builds (Vite/esbuild tolerate the CJS/ESM interop), but any downstream package whose tests run under Vitest and exercise code that imports @freckle/parser fails outright. Hit this bumping @freckle/parser to 3.0.0 across three workspaces in megarepo — see freckle/megarepo#45970 (currently blocked on this).

Suggested fix: import the default and destructure, or import each function from its own entry point:

import lodash from 'lodash'
const {reduce, map: _map, find} = lodash

or

import reduce from 'lodash/reduce'
import _map from 'lodash/map'
import find from 'lodash/find'

— by Claude

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions