Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

cannot find name 'require' in angular 7(typescript 3.1.3)

My question is why this error shown?

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.

I have install

 @types/node
in app/tsconfig.app.json have add 
"types": [
    "node" 
  ],
  "typeRoots": [ 
  "../node_modules/@types"
 ]  

but there is error cannot find 'require'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"]
}

So be sure to add this into both files ./tsconfig.json AND ./src/tsconfig.app.json and it should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...