如何解决由于较旧的节点和 npm 版本,无法在 appspec.yml 中运行应用程序启动脚本无法更新它们
我正在尝试使用 aws 中的代码管道在 EC2 实例上部署应用程序。我为此使用了 codedeploy。我能够成功地从 github 获取应用程序并使用 codebuild 构建它,但它在部署时失败并出现以下错误。我无法理解问题是什么。我已经尝试在 buildspec.yml 文件中更新 node 和 npm,但 appspec.yml 仍然无法提取 node/npm 的更新版本。我是 aws 的新手。有谁知道它从哪里提取这些版本以及如何覆盖它们?附上错误。我的 package.json。 appspec.yml。构建规范.yml。 application_start.sh 和 builspec_yml.sh。
这里是错误
[stderr]npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "server"
[stderr]npm ERR! node v6.17.1
[stderr]npm ERR! npm v3.10.10
[stderr]npm ERR! code ELIFECYCLE
[stderr]npm ERR! react-tmp@1.0.0 server: `node server.js`
[stderr]npm ERR! Exit status 1
[stderr]npm ERR!
[stderr]npm ERR! Failed at the react-tmp@1.0.0 server script 'node server.js'.
[stderr]npm ERR! Make sure you have the latest version of node.js and npm installed.
[stderr]npm ERR! If you do,this is most likely a problem with the react-tmp package,[stderr]npm ERR! not with npm itself.
[stderr]npm ERR! Tell the author that this fails on your system:
[stderr]npm ERR! node server.js
[stderr]npm ERR! You can get information on how to open an issue for this project with:
[stderr]npm ERR! npm bugs react-tmp
[stderr]npm ERR! Or if that isn't available,you can get their info via:
[stderr]npm ERR! npm owner ls react-tmp
[stderr]npm ERR! There is likely additional logging output above.
[stderr]npm WARN Local package.json exists,but node_modules missing,did you mean to install?
[stderr]npm ERR! Linux 4.14.209-160.339.amzn2.x86_64
[stderr]npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "server"
[stderr]npm ERR! node v6.17.1
[stderr]npm ERR! npm v3.10.10
[stderr]npm ERR! path npm-debug.log.4097552080
[stderr]npm ERR! code EACCES
[stderr]npm ERR! errno -13
[stderr]npm ERR! syscall open
[stderr]
[stderr]npm ERR! Error: EACCES: permission denied,open 'npm-debug.log.4097552080'
[stderr]npm ERR! at Error (native)
[stderr]npm ERR! { Error: EACCES: permission denied,open 'npm-debug.log.4097552080'
[stderr]npm ERR! at Error (native)
[stderr]npm ERR! errno: -13,[stderr]npm ERR! code: 'EACCES',[stderr]npm ERR! syscall: 'open',[stderr]npm ERR! path: 'npm-debug.log.4097552080' }
[stderr]npm ERR!
[stderr]npm ERR! Please try running this command again as root/Administrator.
[stderr]
[stderr]npm ERR! Please include the following file with any support request:
[stderr]npm ERR! /var/www/html/npm-debug.log
appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/
hooks:
ApplicationStart:
- location: scripts/application_start.sh
timeout: 300
runas: ec2-user
application_start.sh:
#!/bin/bash
# Stop all servers and start the server as a daemon
cd /var/www/html/
forever stopall
nohup npm run server
buildspec.yml:
version: 0.2
phases:
install:
commands:
- chmod +x scripts/buildspec_yml.sh
- scripts/buildspec_yml.sh
build:
commands:
- npm run start
artifacts:
files:
- '**/*'
scripts/builspec_yml.sh:
#!/bin/bash
nvm install 14.4.0
npm install -g npm@latest
npm i forever -g
感谢您对此进行调查
解决方法
与 aws 没有任何关系,查看您的 scripts/builspec_yml.sh
脚本,您似乎忘记指示 nvm 您希望 use
您安装的版本。试试...
#!/bin/bash
# install and use node version
nvm install 14.4.0
nvm use 14.4.0
# print node and npm version
node --version
npm --version
# upgrade npm and install forever
npm install -g npm@latest
npm install -g forever
如果您使用的是 nvm,我会建议您使用 .nvmrc
并在那里指定节点版本
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。