不知何故,VSCode 中的 Angular (v11.0.4) 语言服务不再起作用。我收到以下错误消息。:
[Info - 17:52:04] Angular language server process ID: 147359
[Info - 17:52:04] Using typescript/lib/tsserverlibrary v4.0.5 from ~/.vscode-oss/extensions/angular.ng-template-0.1100.2/node_modules/typescript/lib/tsserverlibrary.js
[Info - 17:52:04] Using @angular/language-service v11.0.3 from ~/.vscode-oss/extensions/angular.ng-template-0.1100.2/server/node_modules/@angular/language-service/bundles/language-service.js
[Info - 17:52:04] Log file: ~/.config/Code - OSS/logs/20210112T090839/exthost2/Angular.ng-template/nglangsvc.log
[Info - 17:52:06] Disabling language service for ~/Workspace/NG_PROJECT/tsconfig.json because it is not an Angular project ('@angular/core/core.d.ts' could not be found). If you believe you are seeing this message in error, please reinstall the packages in your package.json.
[Error - 17:52:06] Failed to …Run Code Online (Sandbox Code Playgroud) tsconfig visual-studio-code angular angular-language-service angular11
在升级到 Angular 11 之前,我通过以下命令运行了代码覆盖率的单元测试:
ng test --project my-app --code-coverage true
Run Code Online (Sandbox Code Playgroud)
当我将我的项目升级到 Angular 11 时,我仍然能够进行我的代码覆盖率测试,但是我开始收到一条消息,说“'karma-coverage-istanbul-reporter' 的使用自版本 11 以来已被弃用”。它要求我安装 karma-coverage 并更新 karma.conf.js。所以我做了它所要求的。我通过以下命令安装了 karma-coverage 和 karma:
npm install karma karma-coverage --save-dev
Run Code Online (Sandbox Code Playgroud)
结果,我在 package.json 中的 devDependencies 下看到了 karma 条目:
ng test --project my-app --code-coverage true
Run Code Online (Sandbox Code Playgroud)
我更新了我的 karma.conf.js 文件。以下是存在的内容,除了我的评论外,一切都和原来一样:
npm install karma karma-coverage --save-dev
Run Code Online (Sandbox Code Playgroud)
进行此更新后,发生了两件事,我不知道为什么。
当我运行正常的代码覆盖率命令时,我收到以下错误:“服务器在端口 9876 上启动失败:错误:必须安装 karma-coverage 才能运行代码覆盖率。” 我确实安装了它,正如我的 package.json 所示,但由于某种原因,我的项目无法识别这一点。此外,如果我将 karma-coverage-istanbul-reporter require 方法添加回我的 conf.js 文件,coverage 工作正常,但我仍然收到该弃用消息。谁能向我解释为什么我可能会收到此错误?
当我在没有覆盖的情况下运行测试时,我现在收到多个以前从未收到过的警告,例如:“无法从文件扩展名确定文件类型,默认为 js。要使警告静音,请指定 C:/Angular/ 的有效类型配置文件中的 my-project/projects/my-app/src/app/app.component.spec.ts。” 我需要做什么来解决这个问题?
编辑:我找到了答案。在coverageReporter 对象中,您需要将fixWebpackSourcePaths 属性添加为true:
"karma": "^5.2.3",<br>
"karma-coverage": "^2.0.3"
Run Code Online (Sandbox Code Playgroud) unit-testing karma-jasmine karma-coverage angular-cli angular11
我在我的机器上使用 angular 11.2,我想运行一个 angular 12 项目。从 git 克隆后,我运行了以下命令。
npm installng serve但是我遇到了以下错误并且无法运行该项目。我读了这个问题,但它对我不起作用。
Error: ./src/main.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Error: ./src/polyfills.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Error: (webpack)-dev-server/client?http://0.0.0.0:0&sockPath=/sockjs-node
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
在将现有应用程序迁移到 Angular 11 时,我面临以下错误:
Error: The Angular Compiler requires TypeScript >=4.0.0 and <4.1.0 but 4.1.2 was found instead.
Run Code Online (Sandbox Code Playgroud)
我不确定 4.1.2 依赖项来自哪里。从全局安装运行 tsc 返回 4.0.5:
tsc --version
Version 4.0.5
Run Code Online (Sandbox Code Playgroud)
运行本地版本返回相同的值:
npx tsc --version 版本 4.0.5
我知道我可以禁用 TS 版本检查,但我真的很想知道 4.1.2 版本的来源。
想法?
问题
我正在尝试从 Angular V9 升级到 V11,但由于以下错误而苦苦挣扎
Namespace node_module/@angular/core/core has no exported member ??FactoryDeclaration
Namespace node_module/@angular/core/core has no exported member ??InjectorDeclaration
Namespace node_module/@angular/core/core has no exported member ??NgModuleDeclaration
Namespace node_module/@angular/core/core has no exported member ???ComponentDeclaration
但我不完全确定这意味着什么以及如何解决它。
我试过的
我看过一个类似的问题:Ng serve throwing @angular/core/core 没有导出成员 'eeFactoryDef'这是我能找到的唯一线索,但它并没有真正帮助我。
我尝试删除我的整个 node_modules 文件夹并使用npm i. 我也试过npm ci了。我也尝试添加
"@angular/core/*": [
"./node_modules/@angular/core/*"
]
Run Code Online (Sandbox Code Playgroud)
或者
"@angular/*": [
"./node_modules/@angular/*"
]
Run Code Online (Sandbox Code Playgroud)
到我的tsconfig.json,但这也没有帮助。
我认为是什么问题
我对此一无所知,但我认为我的 NPM 依赖项的路径有问题,因为它引用了@angular/core/core,但我的node_modules.
如果我转到node_modules/@angular/core/core.d.ts我认为是/core/core路径的文件,尽管我不确定这一点,然后我也会在那里看到相同的错误,这让我更加困惑,因为我认为问题出在 Angular …
我有一个 Angular 11 应用程序,正在使用以下命令构建用于在生产中部署:
npm install
npm run build -- --prod --outputHashing=all
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,部署后,当我使用浏览器访问应用程序的 URL 时,我仍然看到该应用程序的旧版本。
我最初认为这是一个缓存问题,即使我使用该--outputHashing=all选项进行编译(据我所知,该选项似乎正在工作,dist文件夹中的输出文件似乎具有随机文件名)。情况似乎是这样:如果我在 Chrome 开发选项中禁用缓存后刷新页面,它现在会显示更新的应用程序。
然而,问题是:如果我关闭浏览器并再次打开它......我会回到旧的应用程序!因此,清除缓存似乎是一种临时解决方案。
经过进一步调查,我怀疑它与 Angular 相关service workers,因为当我打开 Chrome 的开发工具加载页面时,我可以看到很多网络调用被标记为Served from service worker.
然而,我还不够 Angular 专家,不知道如何进一步诊断。我已经阅读了 Angular 网站上有关 Service Worker 的文档,但它并没有帮助我弄清楚问题到底出在哪里。有人能指出我正确的方向吗?这是我的服务工作线程配置文件,它是在创建应用程序时自动生成的。如果我还需要提供其他文件,请告诉我:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**", …Run Code Online (Sandbox Code Playgroud) 为什么 angular 编译器找不到GeolocationPositionand GeolocationPositionError?VSC 不会出错,只有在编译过程中才会出错。
Error: src/app/modules/shared/services/position.service.ts:10:46 - error TS2304: Cannot find name 'GeolocationPosition'.
10 private positionSource = new ReplaySubject<GeolocationPosition>(1);
Run Code Online (Sandbox Code Playgroud)
我通过any输入类型来解决这个问题,但我只是好奇为什么 Angular 会给我这个错误以及我如何解决这个问题。
我已经尝试了不同的编译器目标 ( es5, es6, es2018) 但没有运气。已经安装@types/core-js但也没有任何运气。是否有我遗漏的 @types 模块?
这是我当前的 tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"module": "es2020",
"lib": [
"es2018",
"dom" …Run Code Online (Sandbox Code Playgroud) 我使用 npm 安装了 agm/core,如下所示:
npm install @agm/core
Run Code Online (Sandbox Code Playgroud)
显示以下警告:
npm WARN @agm/core@3.0.0-beta.0 requires a peer of @angular/common@^9.1.0 || ^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @agm/core@3.0.0-beta.0 requires a peer of @angular/core@^9.1.0 || ^10.0.0 but none is installed. You must install peer dependencies yourself.
Run Code Online (Sandbox Code Playgroud)
尽管如此,我还是继续按照如下文档将 AgmCoreModule 导入 AppModule:
AgmCoreModule.forRoot({
apiKey: 'MY MAP KEY',
libraries: ['places']
})
Run Code Online (Sandbox Code Playgroud)
但是,当尝试使用ng serve为应用程序提供服务时,会出现以下错误:
Error: node_modules/@agm/core/lib/services/google-maps-api-wrapper.d.ts:50:41 - error TS2314: Generic type 'MapHandlerMap<T>' requires 1 type argument(s).
50 subscribeToMapEvent<N …Run Code Online (Sandbox Code Playgroud) 我在 Angular 10.2.4 上有一个 asp.net core 应用程序,决定升级到 11。 Ran:ng update @angular/core@11 @angular/cli@11它抱怨 devkit 失败。卸载了devkit,将角度升级到11.2.14 OK。
现在我正在尝试重新安装 devkit。
npm install @angular-devkit/build-angular --save-dev- 失败 - 似乎尝试安装 v12 并且也依赖于 cli 12。
npm install @angular-devkit/build-angular@11.2 --save-dev或npm install @angular-devkit/build-angular@11 --save-dev- 失败 - 未找到 @angular-devkit/build-angular@xx 的匹配版本
适用于 Angular 11 的 devkit 版本是什么?关于如何查找/推断/猜测某个 Angular 版本的包的正确版本的一般想法是什么?
我在角度应用程序中工作,其中使用 valueChanges 方法来检测更改。喜欢 :
this.MyFrm.controls['is_applicable'].valueChanges.subscribe(values => {
this.mainFunc()
});
Run Code Online (Sandbox Code Playgroud)
但它触发了这个函数两次,为了解决这个问题,我使用了 debounceTime。喜欢 :
this.MyFrm.controls['is_applicable'].valueChanges.pipe(debounceTime(0),distinctUntilChanged(),takeUntil(this.destroy$)).subscribe(values => {
this.mainFunc()
});
Run Code Online (Sandbox Code Playgroud)
但现在出现了 valueChanges 一段时间后触发的问题,这破坏了我的代码流。
有什么建议吗?
angular11 ×10
angular ×9
typescript ×4
npm ×2
agm ×1
angular-cli ×1
angular-ivy ×1
geolocation ×1
package.json ×1
tsconfig ×1
unit-testing ×1