编译项目时出现下一个错误:
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.
我该如何解决?我尝试删除的node_modules并重新安装。但这对我没有帮助。
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"
},
能帮助别人吗?
答案 0 :(得分:0)
这可能是因为您的TypeScript版本需要更新。
在此处查看此问题:#42301181 Initializers are not allowed in ambient contexts
尝试使用最新版本的TypeScript编译项目。
答案 1 :(得分:0)