【问题标题】:Node.js deployment fails on Amazon Elastic Beanstalk due to directory permissions由于目录权限,在 Amazon Elastic Beanstalk 上的 Node.js 部署失败
【发布时间】:2016-07-08 13:33:28
【问题描述】:

我正在尝试使用命令行工具在 Elastic Beanstalk 上安装一个简单的 Node.js 应用程序。

在我的 git 存储库中,我运行命令

$ eb deploy

部署我的 git 存储库的内容。它部署良好,但应用程序的健康状态为红色。

如果我查看 Elastic Beanstalk 网站上的日志,我会发现日志中出现以下错误:

> fsevents@1.0.8 install /tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/build'
gyp ERR! stack at Error (native)
gyp ERR! System Linux 4.1.17-22.30.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-linux-x64/fse.node" "--module_name=fse" "--module_path=/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-linux-x64"
gyp ERR! cwd /tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents
gyp ERR! node -v v4.3.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok 

我尝试了各种方法,例如:

  1. 自己创建目录(目录归根用户所有)。
  2. 从 /tmp 中删除所有内容,以便下次它自行修复。
  3. 删除我的 node_modules 目录。

这些选项都不起作用,我找不到解决方法或发生这种情况的原因。我可以在本地运行 node.js 应用程序,也可以毫无问题地将其部署到 Azure 和 Heroku。

【问题讨论】:

  • 我也遇到了同样的问题,你有什么发现吗?建议的答案不是我的问题
  • 我已经弄清楚了,一个模块试图在 package.json 的 preinstall 部分中使用 npm install 安装另一个模块。希望这也是你的问题。
  • 我通过不在 git 存储库中签入 node_modules 解决了我的问题。 npm install 自动创建它们。

标签: node.js amazon-web-services amazon-elastic-beanstalk npm-install


【解决方案1】:

花了一整天的时间来调试这个错误。事实证明,您的 .ebignore 文件中的目录需要一个斜杠。

.ebignore

node_modules/

如果没有尾部斜杠,您的本地 node_modules 文件夹将由 eb 上传 - 包括开发依赖项。

【讨论】:

  • 最好将node_modules 添加到您的.gitignore 文件中。这解决了这个问题。
  • 你是对的 - 这也将解决问题。我有一个.gitignore,但需要一个单独的.ebignore 才能上传一些也在.gitignore 中的构建文件。文档声称 .ebignore 遵循与 .gitignore 相同的语法,但这并不完全正确
【解决方案2】:

我遇到了类似的问题,但没有使用 eb 进行部署,也没有在包中包含 node_modules/。对我有用的解决方案是在.npmrc 中设置unsafe-perm=true - 请参阅Beanstalk: Node.js deployment - node-gyp fails due to permission denied

【讨论】:

    猜你喜欢
    • 2013-03-05
    • 2018-10-01
    • 2021-03-02
    • 2021-06-21
    • 2013-06-14
    • 2015-12-15
    • 2013-08-13
    • 2014-03-31
    • 1970-01-01
    相关资源
    最近更新 更多