0

我有一个包含 2 个项目的 Nx monorepo。当我在本地构建这些项目时,一切都按预期工作,但是当我尝试在构建服务器上构建相同的项目时,我得到了错误

Another process, with id 111, is currently running ngcc.
Waiting up to 250s for it to finish.
(If you are sure no ngcc process is running then you should delete the lock-file at /opt/atlassian/pipelines/agent/build/node_modules/.ngcc_lock_file.)

这可能是由 command 引起的nx affected:build --all --parallel --configuration=production。这会并行运行所有构建,以某种方式同时运行两个构建ngcc,从而锁定目录中的某些文件node_modules。我很清楚。但问题是我已经尝试了几乎所有建议的修复程序,但警告仍然存在,显着减慢了构建速度,甚至在某些情况下使其失败。


版本

  • Angular:13.2.x(它在 v12.x 上给出了同样的错误)
  • Nx:13.8.x
  • 节点:v14.17.x
  • 管道:Bitbucket 管道

将 ngcc 添加到安装后

根据一些答案(herehereherehere等等),最好的解决方法是添加ngcc --properties es2015 browser module main甚至添加ngcc --properties es2015 browser module main --create-ivy-entry-points --first-onlypostinstallpackage.json 中。由于 Nx V12,这是在通过 Nx 生成新的 monorepo 时自动添加的,但似乎没有修复构建服务器上的消息(本地从未有任何问题)

( "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main",)

删除锁定文件

我试图在构建开始之前删除锁定文件,因为我认为可能postinstall会创建锁定文件,但不知何故没有时间删除它。但是我所有的尝试都表明在构建开始之前没有锁定文件。

脚本:

if [ -f "$BITBUCKET_CLONE_DIR/$NGCC_LOCATION" ]; then rm $BITBUCKET_CLONE_DIR/$NGCC_LOCATION; else echo "no lock-file"; fi

$NGCC_LOCATION="node_modules/.ngcc_lock_file."

总是导致no lock file


缓存

node_modules 缓存在构建服务器中,因此可以在单独的管道步骤中使用。脚本如下:

pipelines:
  pull-requests:
    '**':
      - step: *install
      - parallel:
          - step: *lint
          - step: *test
          - step: *build

每个步骤都使用在-stepnode上创建的缓存。install我无法验证 ngcc 结果是否存储在缓存中,但是由于在node_modules安装步骤之后整个缓存都被缓存并且 ngcc 结果被添加到 node_modules 我猜它被存储了。


由于以上都没有修复警告,我是否缺少某些东西,或者这只是 ngcc 现在的工作方式?

4

0 回答 0