3

When i compiling my project i have next error:


ERROR in node_modules/@angular/common/http/src/response.d.ts(253,21): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@angular/common/http/src/response.d.ts(259,19): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@angular/core/src/application_init.d.ts(26,21): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@angular/core/src/ivy_switch/compiler/ivy_switch_on.d.ts(12,35): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
node_modules/@angular/core/src/ivy_switch/compiler/legacy.d.ts(19,35): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
node_modules/@angular/core/src/linker/query_list.d.ts(36,22): error TS1039: Initializers are not allowed in ambient contexts.

how can i fix this? I tryed deleted node_modules and reinstall it. But its not help for me.

Package.json:

"dependencies": {
    "@angular/animations": "^7.0.4",
    "@angular/cdk": "^7.2.2",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "^7.0.4",
    "@angular/material": "^7.2.2",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@fortawesome/fontawesome-free": "^5.5.0",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "highlight.js": "^9.13.1",
    "material-icons": "^0.2.3",
    "ng2-file-upload": "latest",
    "ngx-highlightjs": "^3.0.0",
    "roboto-fontface": "^0.10.0",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },

Can any help someone?

3 Answers3

0

This could be because your version of TypeScript needs to be updated.

See this question here: #42301181 Initializers are not allowed in ambient contexts

Try compiling your project with the newest version of TypeScript.

Trevor
  • 481
  • 10
  • 25
0

I had the same issue and I solved it updating typescript version:

enter image description here

After change it delete node_modules folder, restore it back using npm install and rebuild solution.

Sergio M.
  • 88
  • 1
  • 7
0

I resolved this by adding :

skipLibCheck": true

to the compiler options in the tsconfig.json.

Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42
Tom Trost
  • 9
  • 3