Ionic找不到名称'require'@ types / node已安装

时间:2019-07-25 04:03:11

标签: angular ionic-framework

此代码在我的Angular项目中有效。我必须安装“ @ types / node”:“ ^ 8.9.5”并将该类型添加到我的tsconfig中,以阻止它引发错误。

我在Ionic中遇到了同样的错误,默认情况下安装了“ @ types / node”:“〜12.6.6”。如果我尝试运行“ npm install @ types / node”,则会引发错误。

项目正在运行,我只是无法构建项目。

编译错误:

ERROR in error TS2688: Cannot find type definition file for 'node'.
src/app/pages/get-member-details/get-member-details.page.ts(63,37): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`.

代码:

    import * as i18nIsoCountries from 'i18n-iso-countries';

    async ngOnInit() {
//THIS IS LINE 63 BELOW
        i18nIsoCountries.registerLocale(require('i18n-iso-countries/langs/en.json'));
        const indexedArray = i18nIsoCountries.getNames('en');
        for (const key in indexedArray) {
          const value = indexedArray[key];
          this.countries.push(value);
        }
      }

1 个答案:

答案 0 :(得分:0)

在node_modules文件夹下,@ types / node文件夹为空。 它可能搞砸了安装。我必须删除该文件夹并重新安装。 现在正在工作。