当我编译我的项目时出现下一个错误:
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"
},
有什么可以帮助别人的吗?
最佳答案
这可能是因为您的 TypeScript 版本需要更新。
在这里查看这个问题:#42301181 Initializers are not allowed in ambient contexts
尝试使用最新版本的 TypeScript 编译您的项目。
https://stackoverflow.com/questions/54370109/
相关文章:
laravel - 在 Scout 中使用更复杂的 where 子句
java - MockMvcRequestBuilders.asyncDispatch 提供一个空的
jquery - Parsley.js isValid() 使用自定义验证器返回 null
nginx - 使用 apollo 客户端从 nextjs 中的 getInitialProps 方
angular6 - 我想根据复选框选择显示/隐藏 Angular 6 react 形式组
maven - 如何重定向 maven surefire 插件 stdout*deferred 临时
c# - 继续获取 "Unable to load DLL ' SQLite.Interop.dll