简体   繁体   English

Angular CLI项目编译失败

[英]Angular CLI project failed to compile

I've searched all the web but find not relevant solution.我搜索了所有 web 但没有找到相关的解决方案。 I've uninstalled both @angular/cli and node.js, cleared cache and reinstalled the latest version for the two both as an admin and non-admin yet no result.我已经卸载了@angular/cli 和 node.js,清除了缓存并以管理员和非管理员身份重新安装了两者的最新版本,但没有结果。 Below is the error message:以下是错误消息:

ERROR in./node_modules/core-js/modules/es6.regexp.exec.js 1:2 Module parse failed: Unexpected character '�' (1:2) /node_modules/core-js/modules/es6.regexp.exec.js 中的错误 1:2 模块解析失败:意外字符“�”(1:2)
You may need an appropriate loader to handle this file type.您可能需要适当的加载程序来处理此文件类型。
(Source code omitted for this binary file) (此二进制文件省略了源代码)
i 「wdm」: Failed to compile. i 「wdm」:编译失败。

Sometimes it brings this after working on a particular project thereby causing me not to continue it.有时它会在完成一个特定项目后带来这个,从而导致我不再继续它。 I create another one and it might even not compile at all.我创建了另一个,它甚至可能根本无法编译。 I've created several projects now and all I get is this error during compilation.我现在已经创建了几个项目,我得到的只是编译过程中的这个错误。

I also noticed that it's only when I create a new Angular project while connected to the internet will it create else it will not and even stayed longer than expected during the creation.我还注意到,只有当我创建一个新的 Angular 项目并连接到互联网时,它才会创建,否则它不会甚至在创建过程中停留的时间比预期的要长。

I had the same issue this morning and I was able to solve it.今天早上我遇到了同样的问题,我能够解决它。 Follow these steps:按着这些次序:

  1. Uninstall Node by using an app cleaner eg IObit Uninstaller Pro (The pro version will delete all folders associated with node eg npm, npm-cache. Also scan for those folders in case there are still some few leftovers.)使用应用程序清理器卸载节点,例如 IObit Uninstaller Pro(专业版将删除与节点关联的所有文件夹,例如 npm、npm-cache。同时扫描这些文件夹以防仍有一些剩余物。)

  2. Restart your pc.重启你的电脑。

  3. Go over to Nodejs.org and download Node 14.16, not the latest version. Go 到 Nodejs.org 并下载 Node 14.16,而不是最新版本。 The latest is Node 14.17.最新的是节点 14.17。

  4. Install Node which you downloaded.安装您下载的节点。

  5. Launch CMD.启动 CMD。

  6. Run npm i.运行 npm i。

  7. After that, run npm i -g @angular/cli.之后,运行 npm i -g @angular/cli。 This will install angular/cli 12.0.1 which is compatible with your version of Node.这将安装与您的 Node 版本兼容的 angular/cli 12.0.1。

  8. Create a new angular project by running the command: ng new new-project通过运行以下命令创建一个新的 angular 项目:ng new new-project

  9. After successful install, change directory to your new created directory and run the command: ng serve --o安装成功后,将目录切换到新创建的目录并运行命令:ng serve --o

All those "failed to compile" errors wiil never happen again and your browser would display your web project.所有那些“编译失败”的错误都不会再发生,您的浏览器将显示您的 web 项目。

The latest version of node is very buggy and I have actually relayed the matter to the nodejs developers community, commended them for the good job they do BUT asked them to get their acts together.最新版本的 node 有很多 bug,实际上我已经将此事转达给 nodejs 开发者社区,赞扬他们所做的出色工作,但要求他们齐心协力。 I have lost so many projects due bugs which brought many issues similar to this.由于错误带来了许多与此类似的问题,我失去了很多项目。

在您的项目目录中尝试运行ng update --all --force

删除node_modules文件夹,然后重试npm install

first remove node module and Uninstall the node 首先删除节点模块并卸载节点

reinstall the application angular.io with globally than 重新安装应用程序angular.io与全局

npm install -g @angular/cli npm install -g @ angular / cli

so simple: just update core-js from this simple command: 如此简单:只需通过以下简单命令即可更新core-js:

npm i core-js

no need to remove modules or reinstall or any of that 无需删除模块或重新安装或任何

had the same issue有同样的问题

Reinstall Node.js重新安装 Node.js

give Node folder access in Ransomware protection在勒索软件保护中授予节点文件夹访问权限

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM