使用AWS Codepipeline构建简单API时的错误,CodeBuild
我一直在尝试从我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您已经找到了答案,但是对于将来的读者来说,它是:
根据此消息,安装失败的原因是因为您在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版本,因此:也最好使用
npm ci
而不是npm npm install
在CI上,因为前者利用了现有的软件包-Lock.json
来确保可生殖的构建。Maybe you found the answer already, but for future readers, here it goes:
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 usingnpm v6.8.x
that comes with that version of node.That version of npm generates/reads
package-lock.json
file with aversion 1
format, while your local npm has generated apackage-lock.json
with theversion 2
format, most certainly because you are onnpm v7 or later
.Solution:
Update npm version in the
pre-build
phase of your Codebuild, as such:Also, it better to use
npm ci
rather thannpm install
on CI, because the former leverage the existingpackage-lock.json
to ensure reproductible builds.