使用AWS Codebuild编译问题(vue.js项目)



我正试图使用AWS Codebuild编译一个vue.js项目,但它在构建阶段被卡住了。它给了我这个错误(用sudo运行(:

[Container]2021/11/26 18:06:02运行命令sudo npm install/codebuild/output/tmp/script.sh:4:/codebuild/out/tmp/sscript.sh:sudo:找不到

〔Container〕2021/11/26 18:06:02命令未成功退出sudonpm安装退出状态127[容器]2021/11/26 18:06:02阶段完成:构建状态:失败[容器]2021/11/26 18:06:02阶段上下文状态代码:COMMAND_EXECUTION_ERROR消息:错误执行命令:sudo npm install。原因:退出状态127

我不知道我是否以错误的方式配置了Codebuild设置。

它给了我这个错误(没有sudo(:

[Container] 2021/11/29 15:06:08 Running command npm run build
> company@0.1.0 build /codebuild/output/src868393770/src
> vue-cli-service build
sh: 1: vue-cli-service: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! company@0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the company@0.1.0 build 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!     /root/.npm/_logs/2021-11-29T15_06_11_998Z-debug.log
[Container] 2021/11/29 15:06:12 Command did not exit successfully npm run build exit status 126
[Container] 2021/11/29 15:06:12 Phase complete: BUILD State: FAILED
[Container] 2021/11/29 15:06:12 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm run build. Reason: exit status 126

或者如果我使用了错误的命令来编译它。buildspec.yml是这样的

version: 0.2
phases:
build:
commands:
- echo Build Phase
- sudo npm install
- sudo npm run build
post_build:
commands:
- echo PostBuild Phase
- aws s3 sync ./dist $S3_BUCKET

如果没有sudo,如错误日志所示,实际错误日志为

/root/.npm/_logs/2021-11-29T15_06_11_998Z-debug.log(文件名将在每次构建时更改。(

如果您可以访问它,您可能会发现错误的实际原因。

如果要共享,请在共享日志之前,确保日志中不包含用户名或其他重要信息。

根据当前信息,错误的原因尚不清楚。然而,我看到过类似错误发生的情况,尽管CodeBuild没有。https://github.com/vuejs/vue-cli/issues/5210

如果源代码包含node_modules目录,请不要包含node_modules文件夹。(这将由npm install创建(


以下是当第一个";sudo npm";出现错误:

也许你不需要sudo来使用npm。

https://docs.aws.amazon.com/codeartifact/latest/ug/using-npm-packages-in-codebuild.html#npm-代码构建中的包登录

这样怎么样。

version: 0.2
phases:
build:
commands:
- echo Build Phase
- npm install
- npm run build
post_build:
commands:
- echo PostBuild Phase
- aws s3 sync ./dist $S3_BUCKET

最新更新