ng build过程不会退出,会停留在终端。

huangapple go评论90阅读模式
英文:

ng build process don't exit and stay in terminal

问题

"build:project:prod": "ng build project --configuration prod --stats-json=true --single-bundle=true && npm run copyAssets"
在将 Angular 升级到 15 版本后,我的构建过程没有在构建完成后退出,因此 copyAssets 甚至没有开始执行。
在终端中,我看到一个包含块文件和一行的表格

Build at: 2023-02-03T15:44:54.029Z - Hash: 5837a5d758832c93 - Time: 7163ms

整个流程由于这个问题而中断。
我应该如何确保整个脚本得到正确执行?

英文:

After updating to Angular 15, my build process

"build:project:prod": "ng build project --configuration prod --stats-json=true --single-bundle=true && npm run copyAssets"

didn't exit after the build, so copyAssets don't even start.
In a terminal, I see a table with a chunk file and a line

Build at: 2023-02-03T15:44:54.029Z - Hash: 5837a5d758832c93 - Time: 7163ms

The whole pipeline is broken down because of it.
How can I ensure that the whole script is executed properly?

答案1

得分: 3

问题的关键在于Node版本。我猜想你可能正在使用"latest"版本的Node,对吗?当我遇到这个问题时,是在本地测试期间,一些构建命令无法执行,因为程序(或运行时的终端)会卡在某些被认为是"completed"任务的地方,通常与构建或奇怪的ng完成脚本有关。但无论如何,这与Angular无关。

为了验证这一点,我反复卸载和安装了各种版本的Angular CLI,但毫无效果。最后,我怀疑这是一个Node版本的问题。在某个时候,我升级了Node到一个不稳定的奇数版本,所以当我回退到Node版本18时,这些问题就消失了。

我的系统是macOS,我使用Homebrew来管理包。这是我所做的:

brew uninstall node
brew install node@18

安装完成后,因为我已经指定了版本,我需要设置环境变量,以防终端无法识别Node。通常,你可以在安装程序后从brew那里得到提示,但由于我使用bash,我修改了.bash_profile文件,并添加了:

export PATH="/usr/local/opt/node@18/bin:$PATH"

这就是处理Node版本问题的方法。至于重新安装Angular CLI,你可以执行以下操作:

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

这应该会将Angular CLI恢复到最新版本。祝你好运!

注意:重要的是要记住,我在这里指定的Node版本是版本18,这是专门为了解决这个特定时点的问题而选择的版本。

英文:

The real issue here is the Node version. I'm guessing you might be using the "latest" version of Node, right? When I encountered this issue, it was during local testing, where some of the build commands wouldn't execute because the program (or the terminal at runtime) would get stuck on some supposed "completed" tasks, usually related to the build or strange ng completion scripts. But anyway, this had nothing to do with Angular.

To verify this, I repeatedly uninstalled and installed various versions of Angular CLI, but to no avail. Finally, I suspected it was a Node version issue. At some point, I had updated Node to an unstable odd version, so when I reverted to Node version 18, these problems disappeared.

My system is macOS, and I manage packages using Homebrew. Here's what I did:

brew uninstall node
brew install node@18

After installation, since I had specified the version, I needed to set environment variables to prevent the terminal from not recognizing Node. Usually, you can get a prompt from brew after installing the program, but since I use bash, I modified the .bash_profile file and added:

export PATH="/usr/local/opt/node@18/bin:$PATH"

That's how to handle Node version issues. As for reinstalling Angular CLI, you can do the following:

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

That should restore Angular CLI to the latest version. Good luck!

Note: It's important to keep in mind that the Node version I specified here is version 18, which was selected specifically to address the issue at this particular point in time.

答案2

得分: 0

尝试逐步运行它,比如首先只是构建: ng build project --configuration prod,然后单独打包,依此类推,这样或许你可以找出阻塞的地方。

英文:

Try run it in steps, like first just de build: ng build project --configuration prod, after se single bundling and so one, in this way maybe you could find out where it is blocked.

huangapple
  • 本文由 发表于 2023年2月6日 15:30:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定