[英]required keyword not working with 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正确安装了它,但没有工作。
require
吗? 使用 ES6 导入。require
,则可以在它之前加上declare const require: any
。 为我工作。如果您想在代码中使用 require ,请按照以下步骤操作
首先安装这个包
npm i -D @types/node
然后在你的 tsconfig.json
"typeRoots": [
"node_modules/@types", //add this
],
而不是使用:
import { Process } from '@types/node';
您需要更改tsconfig.json:
{
"compilerOptions": {
...
"typeRoots": ["node_modules/@types"]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.