Error: Initializers are not allowed in ambient contexts




Asked on March 05, 2017
Hi,
I upgraded my Angular version from version 2.3.0 to 4.0.0-rc.2 ang while compiling, I am getting following error.

Initializers are not allowed in ambient contexts.
node_modules/@angular/common/typings/src/platform_id.d.ts(11,44): error TS1039:
Initializers are not allowed in ambient contexts.
node_modules/@angular/compiler/typings/src/util.d.ts(1,36): error TS1039: Initia
lizers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/animation/animation_metadata_wrapped.d.ts
(12,33): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/animation/dsl.d.ts(34,33): error TS1039:
Initializers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/errors.d.ts(9,33): error TS1039: Initiali
zers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/errors.d.ts(10,43): error TS1039: Initial
izers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/errors.d.ts(11,42): error TS1039: Initial
izers are not allowed in ambient contexts.
node_modules/@angular/core/typings/src/errors.d.ts(12,43): error TS1039: Initial
izers are not allowed in ambient contexts.
node_modules/@angular/platform-browser/typings/src/dom/dom_renderer.d.ts(14,41):
 error TS1039: Initializers are not allowed in ambient contexts.
9:08:23 PM - Compilation complete. Watching for file changes.


What to fix it?



Replied on March 05, 2017
This is because lower version of TypeScript. Use at least Typescript version 2.1.
Find the sample package.json with angular version 4.0.0-rc.2 and TypeScript version 2.2.1.
While compiling there will be no error. 

      package.json

{
  "name": "angular-demo",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc -w"
  },
  "dependencies": {
    "@angular/common": "~4.0.0-rc.2",
    "@angular/compiler": "~4.0.0-rc.2",
    "@angular/core": "~4.0.0-rc.2",
    "@angular/forms": "~4.0.0-rc.2",
    "@angular/http": "~4.0.0-rc.2",
    "@angular/platform-browser": "~4.0.0-rc.2",
    "@angular/platform-browser-dynamic": "~4.0.0-rc.2",
    "@angular/router": "~4.0.0-rc.2",

    "angular-in-memory-web-api": "~0.3.0",
    "systemjs": "0.20.9",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "5.2.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "typescript": "~2.2.1"
  }
}


Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us