Typescript lodash no default export for one function
You can import one function from lodash using import isEqual from 'lodash/isEqual';
in typescript with flag esModuleInterop
in compiler options (tsconfig.json)
example
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"moduleResolution": "node",
"esModuleInterop": true,
...
}
}
source to share
The only way I could solve it was like this:
import get = require("lodash.get");
See a similar example here: https://github.com/DefiniteTyped/DefiniteTyped/issues/14160
Another suggestion, import * as get from 'lodash.get';
it crashes like this if you don't have the correct configuration: TS2497: This module can only be referenced when importing / exporting ECMAScript by enabling the 'esModuleInterop' flag and providing a link to its default export
And in fact, I have this in my tsconfig.json:
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
And it fails anyway (not for React packages, moment and others, but only for this lodash.get package). So the ugly require
does the trick (I mean the ugly just because it breaks ES6 import syntax, which means we're skipping a sequence of code).
source to share