简体   繁体   English

Amazon Elastic Beanstalk npm 找不到 package.json

[英]Amazon Elastic Beanstalk npm cant find package.json

I'm very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk.我对亚马逊网络服务很陌生,我正在尝试在他们的弹性 beantalk 上设置一个 node.js 应用程序。 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:我设置了实例并上传/部署了站点,但是当运行状况“正常”时,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.问题是我的 package.json 确实存在,因为我用 npm init 生成了一个。 Any ideas on why it cant be found?关于为什么找不到它的任何想法? Here is the package.json这是 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"
}

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".例如,您可能将所有文件都放在名为“Project”的文件夹中。 Rather than zipping "Project", you should zip and upload the contents of "Project".您应该压缩并上传“项目”的内容,而不是压缩“项目”。

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

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.我在app.jsserver.js文件顶部附近的端口中修复了这个设置,就在我创建 express 应用程序之后。 For example:例如:

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

I was having these odd error on AWS EB as well.我在 AWS EB 上也遇到了这些奇怪的错误。 I was generally deploying using the CLI.我通常使用 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.确保 package.json 不在您的 .gitignore 文件中,以确保将其提交到您的存储库。 EB uses the git commit history to decide what to zip and send. EB 使用 git 提交历史来决定压缩和发送什么。 If that isnt included it is not on the AWS servers如果不包括在内,则它不在 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.我正在为 EC 使用 t2.nano 实例(512MB 空间)选项,这似乎是一个问题,因为我的 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.不确定这是否是我的问题的根本问题,但是当我升级到至少具有 1GB 空间的实例时,我的错误消息发生了变化。

hope this helps希望这可以帮助

I was having something similar whereby the elastic beanstalk deploy failed when using the eb cli.我遇到了类似的情况,即在使用 eb cli 时,弹性 beantalk 部署失败。 I realized that the elastic beanstalk config files had inadvertently been added to my .gitignore file causing the deploy to fail.我意识到弹性 beanstalk 配置文件无意中被添加到我的 .gitignore 文件中,导致部署失败。

I had trouble with the zipping, etc. I recommend using CodePipeline and linking it to your github or AWS codecommit.我在压缩等方面遇到了问题。我建议使用 CodePipeline 并将其链接到您的 github 或 AWS 代码提交。 Then, skip the build stage, and for the deploy stage click elastic beanstalk.然后,跳过构建阶段,在部署阶段单击弹性 beantalk。

You will have to pause the process and open a new tab and go to EB and create a new environment.您将不得不暂停该过程并打开一个新选项卡,然后转到 EB 并创建一个新环境。 Make sure you click nodeJS in this example.确保在此示例中单击 nodeJS。 Make sure you choose "sample code" so that AWS can set it up with their template.确保您选择“示例代码”,以便 AWS 可以使用他们的模板进行设置。 Once the EB is finished building you should have a link to the template that is functional. EB 构建完成后,您应该有一个指向功能模板的链接。

Then you can go back to your CodePipeline tab and click on Elastic Beanstalk for deployment and you should find the EB you just made.然后您可以返回到您的 CodePipeline 选项卡并单击 Elastic Beanstalk 进行部署,您应该会找到您刚刚制作的 EB。

I recommend this process because it will automatically update every time you do a git change.我推荐这个过程,因为它会在你每次进行 git 更改时自动更新。 This is better than zipping a file, etc.这比压缩文件等要好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM