找不到模块:错误:无法解析“lodash-es”

use*_*469 7 lodash definitelytyped package.json angular

在我的 Angular 8 TypeScript 代码中,我直接导入 lodash (例如import * as _ from 'lodash';)。在我的package.json我有"lodash": "^4.17.15"

我决定安装该@types/lodash-es模块并以这种方式导入特定的 lodash 函数(例如import { map } from 'lodash-es';)。它更好,因为它节省了运行时空间,并且还使用标准的 Angular/TypeScript 导入机制。

但是,现在当我运行构建时,我收到此错误:

Module not found: Error: Can't resolve 'lodash-es'

我该如何修复这个错误?

use*_*469 8

除了安装@types/lodash-es模块外,还需要将现有"lodash": "^4.17.15"模块替换为"lodash-es": "^4.17.15"

这是因为@types/lodash-esrequirelodash-es和 not lodash。一旦你知道了这一点就很明显了,但我最初错过了它。