简体   繁体   English

Angular 9 - NGCC 因未处理的异常而失败

[英]Angular 9 - NGCC fails with an unhandled exception

Building the application after having upgraded dependencies to Angular 9 (and having performed the necessary code changes) throws an error:在将依赖项升级到 Angular 9(并执行必要的代码更改)后构建应用程序会引发错误:

Compiling @angular/animations: es2015 as esm2015 Compiling @angular/animations: es2015 as esm2015 Compiling @angular/core: es2015 as esm2015 Compiling @angular/core: es2015 as esm2015 Compiling @angular/core: es2015 as esm2015 Error : Error on worker #5: TypeError: Cannot read property 'fileName' of null编译@angular/animations: es2015 as esm2015 编译@angular/animations: es2015 as esm2015 编译@angular/core: es2015 as esm2015 编译@angular/core: es2015 as esm2015 编译@angular/core: es2015 as esm2015 Error : Error on worker #5: TypeError: 无法读取 null 的属性 'fileName'

It then goes on to throw the below error:然后它继续抛出以下错误:

Compiling @angular/core: es2015 as esm2015 Compiling @angular/compiler/testing: es2015 as esm2015 Compiling @angular/core: es2015 as esm2015 Error : Tried to write node_modules/@angular/core/core.d.ts.__ivy_ngcc_bak with an ngcc back up file but it already exists so not writing, nor backing up, node_modules/@angular/core/core.d.ts.编译@angular/core: es2015 as esm2015 编译@angular/compiler/testing: es2015 as esm2015 编译@angular/core: es2015 as esm2015错误:试图用一个写node_modules/@angular/core/core.d.ts.__ivy_ngcc_bak ngcc 备份文件,但它已经存在,所以不写入,也不备份,node_modules/@angular/core/core.d.ts。

This error may be because two or more entry-points overlap and ngcc has been asked to process some files more than once.此错误可能是因为两个或多个入口点重叠并且 ngcc 被要求多次处理某些文件。 You should check other entry-points in this package and set up a configuration to ignore any that you are not using.您应该检查此包中的其他入口点并设置配置以忽略任何您不使用的入口点。

Compiling @angular/core: es2015 as esm2015 An unhandled exception occurred: NGCC failed.编译@angular/core: es2015 as esm2015 发生未处理的异常:NGCC 失败。

This problem (NGCC failed) was encountered by me and my colleague developer on our localhost machines.我和我的同事开发人员在我们的本地主机机器上遇到了这个问题(NGCC 失败)。

It would be important to remark that the dev and prod machines were running well.重要的是要注意 dev 和 prod 机器运行良好。

In order to solve this problem we've followed the next steps:为了解决这个问题,我们遵循了以下步骤:

  1. in tsconfig.json , in angularCompilerOptions have set (" enableIvy ": false)tsconfig.json中,在angularCompilerOptions中已设置(“ enableIvy ”:false)
  2. updated the nodeJS to the last version: (executing node -v returned v14.3.0)将nodeJS更新到最新版本:(执行node -v返回v14.3.0)
  3. have deleted the node_modules folder: (executing "rm.\node_modules\" [on windows], make sure it has been deleted successfully)已删除node_modules文件夹:(执行"rm.\node_modules\" [on windows],确保已成功删除)
  4. have installed the packages: (executing npm i )已安装软件包:(执行npm i
  5. here the project is ready to be built.在这里,该项目已准备好构建。 It builds and runs without errors now.它现在可以毫无错误地构建和运行。

I wish this helps you and other people in situations like this.我希望这可以帮助您和其他人在这种情况下。

In my particular case the @angular-devkit/build-angular was updated to " ^0.1001.2 " in my package.json after running the npm audit fix .在我的特殊情况下, @angular-devkit/build-angular在运行npm 审核后更新为“ ^0.1001.2 (This version seems to belong to angular 10, instead of the local projects' angular version (v9.1.7)) (这个版本好像属于angular 10,而不是本地项目的angular版本(v9.1.7))

After reverting this change, everything started working again:恢复此更改后,一切都重新开始工作:

"@angular-devkit/build-angular": " ~0.901.6 " “@angular-devkit/build-angular”:“ ~0.901.6

Using terminal/cmd,使用终端/cmd,

1st Step:第一步:

ng update @angular/cli @angular/core

2nd Step:第二步:

ng update

3rd Step:第三步:

ng serve

Fixed mine.固定我的。

NOTE Your custom css files in bootstrap folder might get deleted.注意引导文件夹中的自定义 css 文件可能会被删除。 Back them up before and place them back after the update!之前备份它们并在更新后将它们放回去!

Try to remove the node_modules folder and run install again:尝试删除node_modules文件夹并再次运行安装:

rm -rf node_modules
npm install

For me it has solved the problem.对我来说它已经解决了这个问题。

This issue is becuase you might be running your app on any port and angular ngcc was assigned with a particular process id which was specified and locked in a file called __ngcc_lock_file__ inside \node_modules\@angular\compiler-cli\ngcc .这个问题是因为您可能在任何端口上运行您的应用程序,并且 angular ngcc 被分配了一个特定的进程 id,该进程 id 被指定并锁定在\node_modules\@angular\compiler-cli\ngcc中名为__ngcc_lock_file__的文件中。 If you are doing a hard system turn off or if your os crashed, this lock file will be there in the node_modules.如果您正在执行硬系统关闭或操作系统崩溃,此锁定文件将在 node_modules 中。 And once you turn on you machine and trying to start the application again, angular cli will check this lock file and trying to find the process id specified in the file.一旦您打开机器并尝试再次启动应用程序,angular cli 将检查此锁定文件并尝试查找文件中指定的进程 ID。 Most of the time that process id will be missing since you did a complete machine restart and it will throw the this error.大多数情况下,由于您重新启动了完整的机器,因此该进程 ID 会丢失,并且会引发此错误。

Solution 1 .解决方案 1 remove node_modules and do npm install删除node_modules并安装 npm

Solution 2 .解决方案 2 Smart solution - delete the lock file as below.智能解决方案 - 删除锁定文件如下。

Go to `\node_modules\@angular\compiler-cli\ngcc`

find the file named __ngcc_lock_file__ delete it.找到名为__ngcc_lock_file__的文件删除它。 Done.完毕。

Happy hacking快乐的黑客

in my case, adding enableIvy: false didn't solve the issue, which was with the Angular Language Service Extension for vsCode (it looks like it's not actually taking the parameter into account).就我而言,添加enableIvy: false并没有解决问题,这与 vsCode 的 Angular 语言服务扩展有关(看起来它实际上并没有考虑到参数)。

The solution has been to downgrade the extension version.解决方案是降级扩展版本。 (v12.0.0 --> v11.2.14 see here to know how ) (v12.0.0 --> v11.2.14 看这里知道如何

Setting "enableIvy": false in tsconfig.json does fix that particular error.在 tsconfig.json 中设置 "enableIvy": false 确实修复了该特定错误。 Isn't Ivy supposed to be usable already?常春藤不是应该已经可以使用了吗?

This answer I found at enter link description here @clement911 answer and it worked for me after a lot of testing我在此处输入链接描述@clement911答案中找到了这个答案,经过大量测试后它对我有用

Adding "postinstall": "ngcc" to "scripts" in package.json helped me to fix this"postinstall": "ngcc"添加到"scripts"帮助我解决了这个问题

Check your node.js version with node -v .使用node -v检查您的 node.js 版本。 And check if Angular 9 is compatible with it.并检查 Angular 9 是否兼容。 Updating node.js to the latest LTS version (12.8.1) worked for me.将 node.js 更新到最新的 LTS 版本 (12.8.1) 对我有用。 I did this with nvm (node version manager).我用 nvm(节点版本管理器)做到了这一点。 Found a good instruction here .在这里找到了一个很好的说明。

  • I removed tslib.js from package.json我从package.json中删除了tslib.js
  • Removed package-lock.json删除了 package-lock.json
  • Deleted node_modules folder删除了 node_modules 文件夹
  • npm i
  • ng serve

Worked for me为我工作

Well in my case I was trying to run an angular project of an older version with a newer version of node.好吧,在我的情况下,我试图用新版本的节点运行旧版本的 angular 项目。 I did this:我这样做了:

Removes all the existing nodule modules.删除所有现有的结节模块。

rm -rf node_modules

update node js to latest将节点 js 更新到最新

npm update
npm install

updates the angular project version to the latest将 angular 项目版本更新到最新

ng update @angular/core

updates the project cli to the latest将项目 cli 更新到最新

ng update @angular/cli

Now start the project现在开始项目

ng-serve

in case version mismatch.. check first version node js and angular js如果版本不匹配.. 检查第一个版本节点 js 和 angular js

then write: npm install =>: ng serve然后写: npm install =>: ng serve

if have port issue: ng server --port 4201如果有端口问题: ng server --port 4201

I had to go into my tsconfig.spec.json file and add我必须将 go 放入我的 tsconfig.spec.json 文件并添加

"angularCompilerOptions": {
    "enableIvy": false
}

It was already in my tsconfig.json file.它已经在我的 tsconfig.json 文件中。

Kinda late on this party, but for older Angular versions, I managed to fix this thru VS extensions.在这个聚会上有点晚了,但是对于旧的 Angular 版本,我设法通过 VS 扩展解决了这个问题。

Angular CLI: 6.1.5 Node: 8.11.4 Angular CLI:6.1.5 节点:8.11.4

Visual studio, angular extension视觉工作室,angular 扩展

Agnular view engine角度视图引擎

Extensions -> Angular Language Service(v12.0.2) -> Extension Settings扩展 -> Angular 语言服务(v12.0.2) -> 扩展设置

  • Under Workspace, put a check on "User Legacy View Engine language service".在 Workspace 下,勾选“User Legacy View Engine language service”。

I had a similar problem,我有类似的问题,

in my case updating NodeJS to new version helped.在我的情况下,将 NodeJS 更新到新版本有帮助。

I generally advise people to make a manual backup of the project after every succeded deployment (locally) because, when you face this kind of problem (everything related to NGCC errors ) you can just hard delete node_modules folder and restore it from you last backup .我通常建议人们在每次成功部署(本地)后手动备份项目,因为当您遇到此类问题(与NGCC errors相关的所有内容)时,您可以硬删除node_modules文件夹并从last backup中恢复它。 and then build again.然后再次构建。

Sometimes, when you cannot afford updating nodeJS to the last version , this solution would be perfect.有时,当您负担不起将nodeJS更新到最新版本时,此解决方案将是完美的。

In my case I installed angular-font-awesome package from npm and then bootstrap, it might got conflicted, I just remove previously installed angular-font-awesome and then done ng build在我的情况下,我从 npm 安装了 angular-font-awesome package 然后引导,它可能会发生冲突,我只是删除以前安装的 angular-font-awesome 然后完成ng build

I had this issue when I ran ionic build while the project built just fine with my colleagues.我在运行ionic build时遇到了这个问题,而项目与我的同事一起构建得很好。 So we ran ng -v to compare our packages.所以我们运行ng -v来比较我们的包。 Turns out I had higher versions of @angular-devkit/build-angular , @angular-devkit/build-optimizer and @angular-devkit/build-webpack , each of them was version 0.1001.2 - our project was running with 0.901.8.原来我有更高版本的@angular-devkit/build-angular@angular-devkit/build-optimizer@angular-devkit/build-webpack ,它们都是 0.1001.2 版本——我们的项目运行的是 0.901。 8.

So I ran npm uninstall @angular-devkit/build-angular 0.1001.2 to uninstall it, and npm install @angular-devkit/build-angular 0.901.8 to downgrade.所以我运行npm uninstall @angular-devkit/build-angular 0.1001.2来卸载它,并npm install @angular-devkit/build-angular 0.901.8来降级。 On running ng -v again, the other 2 had downgraded as well.再次运行ng -v时,其他 2 个也已降级。

Finally, ionic build was a success, We lived happily thereafter.最后, ionic build成功了,我们从此过上了幸福的生活。 till we run into different problems.直到我们遇到不同的问题。 Working packages for our project我们项目的工作包

I got this and other bugs because I tried to update some marginal libraries of Angular 9 application.我得到了这个和其他错误,因为我试图更新 Angular 9 应用程序的一些边缘库。 The errors that subsequently appeared during compilation were senseless in the sense that they did not help to correct the error.随后在编译过程中出现的错误是毫无意义的,因为它们无助于纠正错误。

The solution by deleting "node_modules" and "npm i" does not work, because even though I have the original package.json, "npm i" still installs different versions of the libraries - not the original ones.删除“node_modules”和“npm i”的解决方案不起作用,因为即使我有原始的 package.json,“npm i”仍然安装不同版本的库 - 而不是原始库。 What exactly were the libraries in node_modules originally is not known.最初 node_modules 中的库到底是什么尚不清楚。

The only solution that helped is to restore the node_modules from backup .唯一有帮助的解决方案从备份恢复 node_modules

Otherwise, if you need to update the libraries in the application, take a vacation and prepare some antidepressants, but it still may not help in a matter of days to solve meaningless errors after upgrading the libraries.否则,如果您需要更新应用程序中的库,请假并准备一些抗抑郁药,但在升级库后解决无意义的错误可能仍然无济于事。

There is not situtation where disabling IVY is the best solution.不存在禁用IVY是最佳解决方案的情况。

For windows users:对于 windows 用户:

npm i rimraf -g
rimraf node_modules
npm i

"prettier": "2.2.1", remove this as it is interfare with symantics. "prettier": "2.2.1",删除它,因为它与语义相冲突。

For me it turned out we had used the package-lock.json stated package versioning for a while, and when I tried to delete it due to merge conflicts and recreated it, the error happened.对我来说,原来我们使用了 package-lock.json 声明 package 版本控制一段时间,当我由于合并冲突而试图删除它并重新创建它时,发生了错误。 When going back to the old package-lock.json, the problem was gone.当回到旧的 package-lock.json 时,问题就消失了。 So I started searching:于是我开始搜索:

  • comparing changes between both比较两者之间的变化
  • checking if problem appears in production, too - then it almost can't be a dev dependency检查生产中是否也出现问题 - 那么它几乎不可能是开发依赖
  • sorting out improbable and probable dependencies整理出不太可能和可能的依赖关系

I ended up at the Angular dependencies, more exactly at the @angular/material-moment-adapter having received an update (as we allow it in the package.json) from version 11.2.0 to 11.2.12.我最终找到了 Angular 依赖项,更准确地说是在 @angular/material-moment-adapter 收到了从版本 11.2.0 到 11.2.12 的更新(因为我们在 package.json 中允许它)。

Try to remove angular-font-awesome and run install again:尝试删除 angular-font-awesome 并再次运行安装:

npm uninstall angular-font-awesome ng add @fortawesome/angular-fontawesome@0.6.0 npm 卸载 angular-font-awesome ng 添加@fortawesome/angular-fontawesome@0.6.0

the problem is solved after i removed fontawesome and now Material Icons is my choice for icons.在我删除 fontawesome 后问题就解决了,现在 Material Icons 是我的图标选择。 but i should to say thank you for Font Awesome for many years of free awesome icons:)但我应该感谢 Font Awesome 多年来提供的免费真棒图标:)

In my case, the problem was that my server did not have enough RAM (1 GB), which seems not enough to process a build.就我而言,问题是我的服务器没有足够的 RAM (1 GB),这似乎不足以处理构建。 After increasing to 2 GB, the problem was solved.增加到2 GB后,问题就解决了。

Hope this could help anyone.希望这可以帮助任何人。

For who are using vscode 1.62 or later.适用于使用 vscode 1.62 或更高版本的用户。 None of those answers helped me.这些答案都没有帮助我。 I updated vscode yesterday (10/11/2021) and for some reason my Angular 9 project starts to show "NGCC failed".我昨天(2021 年 10 月 11 日)更新了 vscode,由于某种原因,我的 Angular 9 项目开始显示“NGCC 失败”。 I downgraded vscode to 1.61.2 and everything came back to normal.我将 vscode 降级到 1.61.2,一切恢复正常。

Unfortunately, none of the answers provided above worked.不幸的是,上面提供的答案都没有奏效。

Downgrading typescript (4.8 to 4.6 in my case) resolved the issue.降级typescript (在我的例子中是 4.8 到 4.6)解决了这个问题。

This only woked for me del node_modules npm install enableIvy:false was not support who uses angular v12 or above这只为我唤醒了 del node_modules npm install enableIvy:false was not support who uses angular v12 or above

Replace tsconfig.json by below json content将 tsconfig.json 替换为下面的 json 内容

{
  "compileOnSave": false,
  
  "compilerOptions": {
     "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译 angular 项目时出现“未处理的异常:NGCC 失败” - Compiling angular project with “An unhandled exception occurred: NGCC failed” 发生未处理的异常:NGCC 失败 - An unhandled exception occurred: NGCC failed 发生未处理的异常:找不到模块'@angular/compiler-cli/ngcc' - An unhandled exception occurred: Cannot find module '@angular/compiler-cli/ngcc' 我无法构建和运行 angular 应用程序:“发生未处理的异常:NGCC 失败。” 有没有人有关于如何解决这个问题的建议? - I'm unable to build and run angular application: 'An unhandled exception occurred: NGCC failed.' has anyone got suggestions on how to resolve this? 发生未处理的异常:NGCC 失败 08-20-2020 - An unhandled exception occurred: NGCC failed 08-20-2020 Angular 11 未运行ngcc - Angular 11 is not running ngcc Visual Studio中的默认角度项目模板失败,首次运行时未处理异常 - Default angular project template from Visual Studio fails with exception unhandled on first run Angular9:ngcc 无法运行 - Angular9 : ngcc failing to run angular 项目中 ng lint 期间未处理的异常 - Unhandled exception during ng lint in angular project 使用 ng serve 在 angular 中发生未处理的异常 - An unhandled exception occurred in angular using ng serve
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM