在 angular 7(打字稿 3.1.3)中找不到名称“要求" [英] cannot find name 'require' in angular 7(typescript 3.1.3)
问题描述
我的问题是为什么会显示此错误?
My question is why this error shown?
src/app/p2p/p2p.component.ts(14,16) 中的错误:错误 TS2580:不能查找名称需要".你需要为节点安装类型定义吗?试试 npm i @types/node
.
ERROR in src/app/p2p/p2p.component.ts(14,16): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try
npm i @types/node
.
我已经安装
@types/node
in app/tsconfig.app.json have add
"types": [
"node"
],
"typeRoots": [
"../node_modules/@types"
]
但是出现错误找不到'require'
but there is error cannot find 'require'
推荐答案
将其添加到我的 tsconfig.json 后问题仍然存在,但另外将以下行添加到 tsconfig.app.json 为我解决了它:
The problem also remained after adding it to my tsconfig.json, but additionaly adding the following line to tsconfig.app.json resolved it for me:
{
"compilerOptions": {
"types": ["node"]
}
所以一定要把它添加到两个文件 ./tsconfig.json 和 ./src/tsconfig.app.json 中,它应该可以工作.
So be sure to add this into both files ./tsconfig.json AND ./src/tsconfig.app.json and it should work.
这篇关于在 angular 7(打字稿 3.1.3)中找不到名称“要求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!