require是node.js中常用方法,用于引入模块、 JSON、或本地文件。
Angular使用会报错
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.
解决办法
在tsconfig.app.json文件中
设置
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [
"node"
]
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
网友评论