Amazon Elastic Beanstalk npm找不到package.json

我很新的amazon web services,我想在他们的弹性beanstalk上设置node.js应用程序。 我设置了实例并上传/部署了该站点,但是当健康状况为“好”时,node.js日志显示了这个重复的约30次:

npm ERR! enoent ENOENT: no such file or directory, open '/var/app/current/package.json' npm ERR! enoent This is most likely not a problem with npm itself npm ERR! enoent and is related to npm not being able to find a file. npm ERR! enoent npm ERR! Please include the following file with any support request: npm ERR! /var/app/current/npm-debug.log npm ERR! Linux 4.1.13-19.31.amzn1.x86_64 npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/npm" "start" npm ERR! node v4.2.3 npm ERR! npm v2.14.7 npm ERR! path /var/app/current/package.json npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall open 

问题是我的package.json确实存在,因为我用npm init生成了一个。 任何想法为什么找不到? 这是package.json

 { "name": "testwebsite", "version": "0.0.1", "scripts": { "start": "node server.js" }, "dependencies": { "body-parser": "^1.13.3", "express": "^4.13.3", "express-session": "~1.0.0", "socket.io": "^1.3.7" }, "description": "my website", "author": "Matt", "engines": { "node": ">=0.10.0" }, "main": "server.js", "devDependencies": {}, "license": "ISC" } 

从官方AWS线程[1]看来,(这是我的问题),您可能会压缩顶层目录,而不是压缩源本身。

例如,您可能将所有文件放在名为“Project”的文件夹中。 而不是压缩“项目”,你应该压缩并上传“项目”的内容

[1] https://forums.aws.amazon.com/thread.jspa?messageID=476022

我遇到了一个与此类似的问题,或者与此类似的问题,并且导致我的代码正在侦听自定义端口,而不是Elastic Beanstalk设置为环境variables的端口( 8081 )。

我在我的app.jsserver.js文件顶部附近的端口中修复了这个设置,就在我创build了快速应用之后。 例如:

 var app = express(); app.set('port', (process.env.PORT || 5000)); // 5000 was my original port 

然后在app.listen方法中使用此端口而不是我自己的自定义端口号:

 app.listen(app.get('port'), function () { console.log('Server has started! http://localhost:' + app.get('port') + '/'); }); 

更多细节在这里: http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

我在AWS EB上遇到了这些奇怪的错误。 我通常使用CLI进行部署。

夫妇的事情尝试。

  1. 确保package.json不在你的.gitignore文件中,以确保它被提交到你的仓库。 EB使用git提交历史来决定要压缩和发送的内容。 如果不包含它,则不在AWS服务器上

  2. 我为EC使用t2.nano实例(512MB空间)选项,这似乎是一个问题,因为我的package.json中有很多模块。 不知道这是否是我的悲哀的根本问题,但是当我升级到至less有1GB空间的实例时,我的错误信息发生了变化。

希望这可以帮助