Amazon Elastic Beanstalk npm无法找到package.json

时间:2022-08-25 09:01:37

I'm very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk. I set up the instance and uploaded/deployed the site, but while the health is "Ok" the node.js logs show this repeated about 30 times:

我是非常新的亚马逊网络服务,我正在尝试在他们的弹性beanstalk上设置node.js应用程序。我设置了实例并上传/部署了站点,但是当运行状况为“Ok”时,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

The problem is that my package.json does exist because I generated one with npm init. Any ideas on why it cant be found? Here is the package.json

问题是我的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"
}

3 个解决方案

#1


22  

From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.

从官方的AWS线程[1]来看,你可能正在试图压缩*目录而不是压缩源本身。

For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".

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

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

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

#2


3  

I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).

我遇到的问题与此问题相同或非常相似,这是因为我的代码正在侦听自定义端口,而不是Elastic Beanstalk设置为环境变量的端口(8081)。

I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:

在我创建快速应用程序之后,我在app.js或server.js文件顶部附近的端口修复了此设置。例如:

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

Then using this port in the app.listen method instead of my own custom port number:

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

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

More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

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

#3


1  

I was having these odd error on AWS EB as well. I was generally deploying using the CLI.

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

couple things to try.

几件事要尝试。

  1. make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers

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

  2. i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.

    我正在使用EC的t2.nano实例(512MB空间)选项,这似乎是一个问题,因为我的package.json中有很多模块。不确定这是否是我的困境的根本问题,但当我升级到具有至少1GB空间的实例时,我的错误消息已更改。

hope this helps

希望这可以帮助

#1


22  

From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.

从官方的AWS线程[1]来看,你可能正在试图压缩*目录而不是压缩源本身。

For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".

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

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

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

#2


3  

I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).

我遇到的问题与此问题相同或非常相似,这是因为我的代码正在侦听自定义端口,而不是Elastic Beanstalk设置为环境变量的端口(8081)。

I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:

在我创建快速应用程序之后,我在app.js或server.js文件顶部附近的端口修复了此设置。例如:

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

Then using this port in the app.listen method instead of my own custom port number:

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

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

More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

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

#3


1  

I was having these odd error on AWS EB as well. I was generally deploying using the CLI.

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

couple things to try.

几件事要尝试。

  1. make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers

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

  2. i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.

    我正在使用EC的t2.nano实例(512MB空间)选项,这似乎是一个问题,因为我的package.json中有很多模块。不确定这是否是我的困境的根本问题,但当我升级到具有至少1GB空间的实例时,我的错误消息已更改。

hope this helps

希望这可以帮助