找不到模块“lodash”,但它的工作原理

问题描述 投票:2回答:1

我正在尝试使用使用Webpack构建的TypeScript将lodash导入到Angular2中的文件中。我总是得到一个错误Cannot find module 'lodash'Cannot find module 'lodash/submodule'。但是,代码仍然正常工作,事实上,如果我不做import代码不能正常工作。

import * as lodash from "lodash";
export class SomeService {
  fn(): any {
    return lodash.range(1, 2);
  }
}

这工作正常,但我仍然得到Cannot find module error。我还尝试过import lodash from "lodash"import {range} from "lodash"import * as range from "lodash/range"以及其他一些事情,但无论如何,我总是得到这个错误。

我做过yarn add lodashtypings install lodashnode_modules/lodash存在并且存在node_ modules/lodash/range.js。事实上,import * as moment from "moment"似乎工作正常。

有没有办法让TypeScript停止将此报告为错误?

typescript lodash
1个回答
0
投票

您应该通过以下方式安装@types/lodash软件包: npm install --save @types/lodash

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.