gpt4 book ai didi

angular - 如何解决错误 TS2304 : Cannot find name 'unknown' in a Angular/dotnet project build using the Okta SDK for angular

转载 作者:行者123 更新时间:2023-12-01 16:28:31 26 4
gpt4 key购买 nike

当尝试使用 dotnet 后端构建和运行 Angular 项目时,我收到以下错误。

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};”所需的 Angular 包而发生的。存在于 Okta Angular 示例应用程序中。可以在该示例项目的 app.component.ts 文件中找到此导入的使用。

系统提示我为该导入语句执行的安装包括:

@angular/router
@angular/core
@angular/common

所有这些都是在项目本地安装的,并使用 npm 在全局范围内安装。

IDE - Visual Studio 代码

其他互联网帖子表示,这是由于使用的 Typescript 版本存在问题,因为 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"
}
}

最佳答案

从您的 package.json 看来您仍在使用 typescript@2,因此您可以尝试更新 npm i -D typescript@3 或添加 "skipLibCheck": true 到你的 tsconfig。

关于angular - 如何解决错误 TS2304 : Cannot find name 'unknown' in a Angular/dotnet project build using the Okta SDK for angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57013068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com