Unexpected token 'export' in lodash-es

Jon Sud

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_modules\lodash-es\lodash.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?

felixmosh

From your error, looks like you are trying to load a esm module in node, 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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related