2

我試圖將一個Node.js應用程序部署到彈性beanstalk。問題是,它每次都在啓動腳本中失敗。我將ec2配置爲使用啓動腳本npm start,它執行node app.js(在package.json中定義)。但是,此啓動腳本在ec2中失敗。我得到記錄的錯誤,Elastic Beanstalk在啓動腳本失敗

npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the myProject start script 'node app.js'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the Portfolio package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node app.js 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs myProject 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls myProject 
npm ERR! There is likely additional logging output above. 

這是什麼意思?在我的命令行上運行npm start的壓縮到AWS的同一應用的根目錄中工作正常,在本地主機上運行。我也已經更新兩NPM和Node.js的

這裏是文件結構拉鍊部署:

.ZIP

  • node_modules/
  • 公共/
  • app.js
  • package.json
  • package-lock.json

回答

2

我遇到了Elastic Beanstalk上類似症狀的問題,這是由缺少npm依賴性引起的。一些依賴項本地安裝在node_modules中,但我們全局安裝了一兩個,導致它們在進行部署壓縮時不會被打包。不幸的是Elastic Beanstalk的錯誤信息在這種情況下不是很有用,並且給出了一個通用錯誤。

+0

您是否找到解決方法? –

+0

是的。首先,確保你的項目所依賴的所有npm依賴項都存在於'package.json'文件中。然後將終端或命令行中的目錄切換到您的項目的根目錄並運行'npm install',這將確保您的'node_modules'文件夾填充有'package.json'文件指定的正確依賴關係。看到[這個問題](https://stackoverflow.com/questions/8367031/how-do-i-install-package-json-dependencies-in-the-current-directory-using-npm)獲得更多幫助! –