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

十年热恋 提交于 2019-11-29 06:02:10

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.

Dinesh Ghule

Type node is missing

install @types/node :

npm install --save @types/node

or

yarn add @types/node

edit your src/tsconfig.json adding:

{
    "compilerOptions": {
        "types": ["node"]
    }
}
Vardaan Tyagi

Add the following settings to src/tsconfig.app.json

{
  "compilerOptions": {
    "types": ["node"]
  }
}

Like some other folks, I, too, had added node to the 'types' array in tsconfig and for some reason it made no difference. Knowing full well that this is a hack, here's how I resolved it:

Add this line anywhere above the 'require' statement: declare const require: any;

This is not a real fix, but I don't have the time to battle with this type of plumbing problem right now. I'll come back and deal with it later (or probably not, but that's OK, too)

Bhanuprakash Reddy

Its all because typeScript is not aware of the require keyword so do add a line making typescript aware of require keyword

once its compiled to javascript it knows the require word better and make the work done

declare var require: any;

const pokemon = require('src/assets/pokedex.json');
user10868303

check tsconfig.json too. you need to add the same settings there too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!