4

I have created an angular application where I am doing JSON conversion functionalities like JSON.stringify, JSON.parse I am getting error like Cannot find name 'JSON' and also I am getting error in tsconfig.json like below

Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'esnext.asynciterable'.

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,    
    "target": "es2015",   
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

login.component.ts

 Savesresponse(socialusers: Socialusers) {  
    this.SocialloginService.Savesresponse(socialusers).subscribe((res: any) => {  
      debugger;  
      console.log(res);  
      this.socialusers=res;  
      this.response = res.userDetail;  
      localStorage.setItem('socialusers', JSON.stringify( this.socialusers));  
      console.log(localStorage.setItem('socialusers', JSON.stringify(this.socialusers)));  
      this.router.navigate([`/Dashboard`]);  
    })  
  } 
1
  • Looks like it's rejecting ES2018 and not getting to 'dom'. What version of typescript are you using? Commented Mar 13, 2020 at 4:24

1 Answer 1

5

Add es5 inside lib of compilerOptions

  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "lib": [
      "es5",
      "dom"
    ]
  }
Sign up to request clarification or add additional context in comments.

3 Comments

What if OP wants ES2018?
@prince ERROR in The target entry-point "angular-6-social-login" has missing dependencies: - @angular/core - @angular/common - rxjs
Can you try changing it to esnext or es6 from es5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.