当尝试使用dotnet后端构建和运行角度项目时,出现以下错误。
info: Microsoft.AspNetCore.SpaServices[0]
ERROR in ../../../../node_modules/@angular/common/common.d.ts(1208,17): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/common/common.d.ts(1271,42): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/common/common.d.ts(2423,26): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/core/core.d.ts(214,21): error TS1039: Initializers are not allowed in ambient contexts.
../../../../node_modules/@angular/core/core.d.ts(5347,22): error TS1039: Initializers are not allowed in ambient contexts.
../../../../node_modules/@angular/core/core.d.ts(10292,36): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
../../../../node_modules/@angular/core/core.d.ts(10963,55): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
../../../../node_modules/@angular/core/core.d.ts(11961,12): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/core/core.d.ts(12448,12): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/rxjs/internal/symbol/observable.d.ts(4,9): error TS2687: All declarations of 'observable' must have identical modifiers.
Microsoft.AspNetCore.SpaServices:Information: ERROR in ../../../../node_modules/@angular/common/common.d.ts(1208,17): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/common/common.d.ts(1271,42): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/common/common.d.ts(2423,26): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/core/core.d.ts(214,21): error TS1039: Initializers are not allowed in ambient contexts.
../../../../node_modules/@angular/core/core.d.ts(5347,22): error TS1039: Initializers are not allowed in ambient contexts.
../../../../node_modules/@angular/core/core.d.ts(10292,36): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
../../../../node_modules/@angular/core/core.d.ts(10963,55): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal.
../../../../node_modules/@angular/core/core.d.ts(11961,12): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/@angular/core/core.d.ts(12448,12): error TS2304: Cannot find name 'unknown'.
../../../../node_modules/rxjs/internal/symbol/observable.d.ts(4,9): error TS2687: All declarations of 'observable' must have identical modifiers.
这些错误是由于某些安装尝试添加支持“从@ angular / router”导入{Router}所需的角度包而导致的;” Okta Angular示例应用程序中存在。可以在该示例项目的app.component.ts文件中找到此导入的用法。
系统提示我为该导入语句执行的安装包括:
@angular/router
@angular/core
@angular/common
所有这些都已在项目本地安装,并使用npm在全球安装。
IDE-Visual Studio代码
其他互联网帖子说,这是由于自TypeScript 3.0中添加了“未知”关键字以来,正在使用的Typescript版本存在问题。
我已遵循所有有关在全球和本地再次更新我的打字稿版本的指导。我还安装了tsd-typescript词典程序包,另一篇文章推荐无济于事。我似乎无法摆脱此错误消息。
package.json包括在这里供参考
{
"name": "VerifyMe",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:ssr": "ng run VerifyMe:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "6.1.10",
"@angular/common": "6.1.10",
"@angular/compiler": "6.1.10",
"@angular/core": "6.1.10",
"@angular/forms": "6.1.10",
"@angular/http": "6.1.10",
"@angular/platform-browser": "6.1.10",
"@angular/platform-browser-dynamic": "6.1.10",
"@angular/platform-server": "6.1.10",
"@angular/router": "6.1.10",
"@nguniversal/module-map-ngfactory-loader": "6.0.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26",
"aspnet-prerendering": "^3.0.1",
"bootstrap": "^4.3.1",
"jquery": "3.3.1",
"popper.js": "^1.14.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "6.1.10",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"typescript": "~2.7.2"
},
"optionalDependencies": {
"node-sass": "^4.9.3",
"protractor": "~5.4.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
答案 0 :(得分:0)
在您的package.json
中,您似乎仍在使用typescript @ 2,因此您可以尝试更新npm i -D typescript@3
或将"skipLibCheck": true
添加到tsconfig。
答案 1 :(得分:0)
安装
TS2687:所有“可观察”的声明必须具有相同的含义 修饰符。
手动安装rxjs
和nodejs
npm install --save rxjs
检查版本
rxjs: 6.2.1
@types/node: 10.3.6