【问题标题】:Why does my Angular project pipeline keep failing?为什么我的 Angular 项目管道总是失败?
【发布时间】:2020-12-21 20:29:16
【问题描述】:

我有一个 Angular 项目,我正在尝试使用 git 和 gitlab 标记并推送到开发服务器。

在第四次尝试失败后,我现在对自己做错了什么感到茫然。

这是我的工作日志:

[0KRunning with gitlab-runner 12.9.0 (4c96e5ad)
[0;m[0K  on dev-runner yMELGGtz
[0;msection_start:1608540813:prepare_executor
[0K[0K[36;1mPreparing the "shell" executor[0;m
[0;m[0KUsing Shell executor...
[0;msection_end:1608540813:prepare_executor
[0Ksection_start:1608540813:prepare_script
[0K[0K[36;1mPreparing environment[0;m
[0;mRunning on WIN-AVAH5M2LJ5E...
section_end:1608540814:prepare_script
[0Ksection_start:1608540814:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m
[0;m[32;1mFetching changes with git depth set to 50...[0;m
Reinitialized existing Git repository in C:/runner/builds/yMELGGtz/0/gitlab_username/project_name-auth-front/.git/
From https://gitlab.com/gitlab_username/project_name-auth-front
 * [new ref]         refs/pipelines/232677922 -> refs/pipelines/232677922
 * [new tag]         v20201221.3              -> v20201221.3
[32;1mChecking out 2e8cffbc as v20201221.3...[0;m
Removing node_modules/
git-lfs/2.10.0 (GitHub; windows amd64; go 1.12.7; git a526ba6b)

[32;1mSkipping Git submodules setup[0;m
section_end:1608540861:get_sources
[0Ksection_start:1608540861:restore_cache
[0K[0K[36;1mRestoring cache[0;m
[0;msection_end:1608540862:restore_cache
[0Ksection_start:1608540862:download_artifacts
[0K[0K[36;1mDownloading artifacts[0;m
[0;msection_end:1608540863:download_artifacts
[0Ksection_start:1608540863:build_script
[0K[0K[36;1mRunning before_script and script[0;m
[0;m[32;1m$ npm i[0;m
npm WARN deprecated ini@1.3.5: Please update to ini >=1.3.6 to avoid a prototype pollution issue

> core-js@3.6.5 postinstall C:\runner\builds\yMELGGtz\0\gitlab_username\project_name-auth-front\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> @angular/cli@11.0.4 postinstall C:\runner\builds\yMELGGtz\0\gitlab_username\project_name-auth-front\node_modules\@angular\cli
> node ./bin/postinstall/script.js

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1650 packages from 1206 contributors and audited 1654 packages in 113.077s

79 packages are looking for funding
  run `npm fund` for details

found 3 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
[32;1m$ npm run build-dev[0;m

> project_name-auth@0.0.0 build-dev C:\runner\builds\yMELGGtz\0\gitlab_username\project_name-auth-front
> ng build --hmr --base-href /auth/ --deploy-url /auth/

Unknown option: '--hmr'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project_name-auth@0.0.0 build-dev: `ng build --hmr --base-href /auth/ --deploy-url /auth/`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the project_name-auth@0.0.0 build-dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Windows\system32\config\systemprofile\AppData\Roaming\npm-cache\_logs\2020-12-21T08_56_23_982Z-debug.log
section_end:1608540984:build_script
[0Ksection_start:1608540984:upload_artifacts_on_failure
[0K[0K[36;1mUploading artifacts for failed job[0;m
[0;msection_end:1608540985:upload_artifacts_on_failure
[0K[31;1mERROR: Job failed: exit status 1
[0;m

请注意,我的操作系统是 Ubuntu 20.04,我已将日志中的 gitlab 用户名和项目名称替换为 gitlab_usernameproject_name。 (因为它不是我的项目或我的存储库)

【问题讨论】:

  • 为什么要使用 —hmr 进行生产构建?
  • @MikeOne 所以我猜 hmr 是罪魁祸首?谢谢你。你能告诉我如何在生产构建中禁用它吗?
  • 您的 package.json 中可能有一个名为 build-dev 的运行脚本。-hmr 标志似乎在其中。但是, build-dev 可能是在管道中运行的错误脚本。您可能想要在那里进行生产构建.. 所以像 ng build —prod..
  • @MikeOne 没关系。我刚刚在 package.json 的脚本中找到了它。太感谢了。编辑:在我输入评论的第一部分后,我看到了你的第二条评论。再次感谢。

标签: node.js angular git npm gitlab


【解决方案1】:

扩展 @MikeOne 在评论中所写的内容以及 webpack Hot Module Replacement documentation 中所述的内容,

HMR 不适用于生产环境,这意味着它只能用于 用于开发。

以前,在我的package.json 中,我有:

"scripts": {
    "build": "ng build --prod --hmr --base-href /auth/ --deploy-url /auth/",
    "build-dev": "ng build --hmr --base-href /auth/ --deploy-url /auth/"
  },

所以,我只是将其更改为:

"scripts": {
    "build": "ng build --prod --base-href /auth/ --deploy-url /auth/",
    "build-dev": "ng build --base-href /auth/ --deploy-url /auth/"
  },

它成功了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多