In my Angular 8 TypeScript code I was importing lodash directy (e.g. import * as _ from 'lodash';
). In my package.json
I had "lodash": "^4.17.15"
.
I decided to install the @types/lodash-es
module and import the specific lodash functions that way (e.g. import { map } from 'lodash-es';
). It is better because it saves runtime space and also uses the standard Angular/TypeScript import mechanism.
However, now when I run a build I am getting this error:
Module not found: Error: Can't resolve 'lodash-es'
How can I fix this error?
In addition to installing the @types/lodash-es
module, the existing "lodash": "^4.17.15"
module needs to be replaced with "lodash-es": "^4.17.15"
This is because @types/lodash-es
requires lodash-es
and not lodash
. This is obvious once you know it but I missed it originally.