使用AWS Codepipeline构建简单API时的错误,CodeBuild

发布于 2025-01-29 06:34:34 字数 2138 浏览 5 评论 0原文

我一直在尝试从我的github存储库中为此简单的REST API设置自动数据,但无法停止在“ NPM安装”上误差。这是您带有Express的基本节点项目。这是我的buildSpec.yml:

version: 0.2
phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing
  pre_build:
    commands:
      - echo Installing source NPM dependencies.
      - npm install
  build:
    commands:
      - echo Build started on `date`
      - echo Compiling the Node.js code
      - npm run build
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'

这是AWS CodeBuild的错误PRINOUT:

[Container] 2022/05/15 21:13:45 Running command npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code EEXIST
npm ERR! path /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Refusing to delete /codebuild/output/src331276253/src/node_modules/.bin/nodemon: is outside /codebuild/output/src331276253/src/node_modules/nodemon and not a link
npm ERR! File exists: /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-15T21_13_48_178Z-debug.log

[Container] 2022/05/15 21:13:48 Command did not exit successfully npm install exit status 1
[Container] 2022/05/15 21:13:48 Phase complete: PRE_BUILD State: FAILED
[Container] 2022/05/15 21:13:48 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install. Reason: exit status 1

我认为我按照惯例所规定的100%完成了此操作,除了我的项目结构外。它们不是在“ SRC”中使用我所有的文件,而是项目的根源。

I have been attempting to set up auto-deploy from my github repo for this simple REST API and cannot get it to stop erroring on 'npm install'. It is your basic node project with express. Here is my buildspec.yml:

version: 0.2
phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing
  pre_build:
    commands:
      - echo Installing source NPM dependencies.
      - npm install
  build:
    commands:
      - echo Build started on `date`
      - echo Compiling the Node.js code
      - npm run build
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'

Here is the error prinout from AWS CodeBuild:

[Container] 2022/05/15 21:13:45 Running command npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code EEXIST
npm ERR! path /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Refusing to delete /codebuild/output/src331276253/src/node_modules/.bin/nodemon: is outside /codebuild/output/src331276253/src/node_modules/nodemon and not a link
npm ERR! File exists: /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-15T21_13_48_178Z-debug.log

[Container] 2022/05/15 21:13:48 Command did not exit successfully npm install exit status 1
[Container] 2022/05/15 21:13:48 Phase complete: PRE_BUILD State: FAILED
[Container] 2022/05/15 21:13:48 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install. Reason: exit status 1

I think I've done this 100% as convention dictates, except for maybe my project structure. Rather than having all my files in 'src', they are in the root of the project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2025-02-05 06:34:34

也许您已经找到了答案,但是对于将来的读者来说,它是:

npm警告read-shrinkwrap此版本的npm与lockfileversion@1兼容,但是package-lock.json是为lockfileversion@2生成的。我会尽力而为!

根据此消息,安装失败的原因是因为您在CodeBuild上的本地计算机上使用了不同版本的npm

您的CodeBuild正在使用nodejs:10运行时,因此根据下面的屏幕截图(从 https://nodejs.org/en/download/releases/ ),它必须使用该版本的Node随附的npm v6.8.x

NPM的版本生成/reads package> package> package> package> lock.json pands 使用版本1格式,而您的本地NPM已生成a <代码>包装 - 洛克.json带有版本2格式,最肯定的是,因为您在npm v7或更高版本上

解决方案:

pre-Build阶段中更新NPM版本,因此:

  pre_build:
    commands:
      - echo Installing source NPM dependencies.
      - npm install -g npm@<your_local_version_here>
      - npm ci

也最好使用npm ci而不是npm npm install在CI上,因为前者利用了现有的软件包-Lock.json来确保可生殖的构建。

Maybe you found the answer already, but for future readers, here it goes:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

According to this message, the reason why the install fails is because you used different versions of npm on local machine vs on codebuild.

Your codebuild is using nodejs: 10 runtime, so according to the screenshot below (taken from https://nodejs.org/en/download/releases/), it must be using npm v6.8.x that comes with that version of node.

Node/NPM versions matrix

That version of npm generates/reads package-lock.json file with a version 1 format, while your local npm has generated a package-lock.json with the version 2 format, most certainly because you are on npm v7 or later.

Solution:

Update npm version in the pre-build phase of your Codebuild, as such:

  pre_build:
    commands:
      - echo Installing source NPM dependencies.
      - npm install -g npm@<your_local_version_here>
      - npm ci

Also, it better to use npm ci rather than npm install on CI, because the former leverage the existing package-lock.json to ensure reproductible builds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文