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:
JavaScript
x
8
1
C:..node_moduleslodash-eslodash.js:10
2
export { default as add } from './add.js';
3
^^^^^^
4
SyntaxError: Unexpected token 'export'
5
at wrapSafe (internal/modules/cjs/loader.js:1116:16)
6
at Module._compile (internal/modules/cjs/loader.js:1164:27)
7
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
8
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.