在角7(打字稿3.1.3)中找不到名称'require' [英] cannot find name 'require' in angular 7(typescript 3.1.3)

查看:876
本文介绍了在角7(打字稿3.1.3)中找不到名称'require'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是为什么显示此错误?

My question is why this error shown?

src/app/p2p/p2p.component.ts(14,16)中的

ERROR:错误TS2580:无法 找到名称"require".您是否需要为节点安装类型定义? 尝试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.

这篇关于在角7(打字稿3.1.3)中找不到名称'require'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆