Typescript: TS2304: Cannot find name 'JSON'

Created on 5 Dec 2018  路  6Comments  路  Source: microsoft/TypeScript

Potential bug when upgrading to Angular 7 and Typescript 3.2.0. Using IntelliJ.

TS2304: Cannot find name 'JSON'

screen shot 2018-12-05 at 3 08 26 pm

External

Most helpful comment

I fixed this on an es5 project by adding "es5" to tsconfig.json at compilerOptions.lib:

{
  "files": [
    "src/index.ts"
  ],
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "lib": [
      "es5",
      "dom"
    ]
  }
}

All 6 comments

Deleting node_modules and npm install seems to have fixed it.

Even after deleting node modules and then doing npm install, the error persists.
image

Same for me. Reinstall with npm doesn't work.

I just hit this too for a new project. I have another project that works, but I am running code-server with typescript 3.4.4 building with webpack for node 8. So there are a lot of moving parts. I am going to try to break it down and see if there is rhyme or reason. I see this reported on other projects, and usually, the solution for some people involves a mixture of tsconfig.json tweaks to the library target and installing specific @type/ packages. There doesn't seem to be consistency though, so I think it is a tooling configuration problem.

I'm hitting the same issue as @geiseri
I also see Cannot find name 'document'. Do you need to change your target library? Try changing thelibcompiler option to include 'dom'.ts(2584) even when my lib entry in tsconfig.json includes dom

I fixed this on an es5 project by adding "es5" to tsconfig.json at compilerOptions.lib:

{
  "files": [
    "src/index.ts"
  ],
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "lib": [
      "es5",
      "dom"
    ]
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dlaberge picture dlaberge  路  3Comments

blendsdk picture blendsdk  路  3Comments

jbondc picture jbondc  路  3Comments

siddjain picture siddjain  路  3Comments

manekinekko picture manekinekko  路  3Comments