Skip to content
Advertisement

Unexpected token ‘export’ in lodash-es

I move from lodash to lodash-es in my typescript project .

I installed lodash-es and @types/lodash-es.

But when I compile using webpack my project it throw an error:

C:..node_moduleslodash-eslodash.js:10
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token 'export'
     at wrapSafe (internal/modules/cjs/loader.js:1116:16)
     at Module._compile (internal/modules/cjs/loader.js:1164:27)
     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)

I’m not sure what the problem and how to solve this error?

Advertisement

Answer

From your error, looks like you are trying to load a esm module in node (v14+), by default only latest node version supports this kind of files.

There is no reason to use lodash-es in node enviroment.

The benefit of using lodash-es comes in browser related code, which will be bundled with one of the bundlers & enables a tree-shaking optimization.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement