在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'
如何解决此错误?
答案 0 :(得分:1)
除了安装@types/lodash-es
模块之外,现有的"lodash": "^4.17.15"
模块还需要替换为"lodash-es": "^4.17.15"
这是因为@types/lodash-es
要求lodash-es
而不是lodash
。一旦您知道它就很明显,但是我本来是想念它的。
答案 1 :(得分:0)
试试这个
<块引用>npm install @types/lodash-es --save-dev
如果在此之后您会遇到同样的问题,请检查您在依赖项中的 package.json
<块引用>"lodash-es": "^4.17.20"
如果没有,只需在 cmd 中编写并运行 npm install 。 这对我有用。