required 关键字不适用于 angular

require 关键字不适用于 angular,引发错误:

src/app/app.component.ts(8,16): error TS2591: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

我该如何解决?其实我也用nodejs正确安装了它,但没有工作。


侃侃尔雅
浏览 487回答 2
2回答

慕斯王

正如其他人所说,你需要 require吗?使用 ES6 导入。但是,如果您确实需要require,则可以在它之前加上declare const require: any。为我工作。

千巷猫影

如果您想在代码中使用 require ,请按照以下步骤操作首先安装这个包npm i -D @types/node然后在你的 tsconfig.json"typeRoots": [            "node_modules/@types", //add this        ],
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript