弹性豆茎 npm 失败

Elastic Beanstalk npm failing

我正在尝试将我的应用程序上传到 Elastic Beanstalk,但 npm 安装在 node-pre-gyp install --fallback-to-build 上失败。我尝试了各种版本的节点都无济于事。它似乎试图为 linux 获取一个不存在且不需要的包,它只需要 OSX(它在其中工作正常)。

解决方案似乎是 运行 npm install with the --no-optional flag 但我找不到让 EB 运行 install with this flag 的方法。

此外,此包似乎是业力的依赖项,我在 package.json 文件中仅将其作为开发依赖项。我可以看到 EB 正在使用 --production 标志进行安装,所以我不知道它首先尝试安装它的目的是什么。

任何有关如何解决此问题的想法都将不胜感激。

>     Running npm with --production flag
>       Failed to run npm install. Snapshot logs for more details.
>       Traceback (most recent call last):
>         File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in <module>
>           main()
>         File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 677, in main
>           node_version_manager.run_npm_install(options.app_path)
>         File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 136, in run_npm_install
>           self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
>         File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
>           raise e
>       subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v4.6.1-linux-x64/bin/npm',
> '--production', 'rebuild']' returned non-zero exit status 1
> (ElasticBeanstalk::ExternalInvocationError)
>     caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
>       npm WARN package.json Room@1.0.0 No repository field.
>       npm WARN package.json Room@1.0.0 No README data
>       npm WARN package.json Room@1.0.0 No license field.
>       
>       > uglifyjs-webpack-plugin@0.2.1 postinstall /tmp/deployment/application/node_modules/uglifyjs-webpack-plugin
>       > node lib/post_install.js
>       
>       
>       > fsevents@1.0.15 install /tmp/deployment/application/node_modules/karma/node_modules/chokidar/node_modules/fsevents
>       > node-pre-gyp install --fallback-to-build
>       
>       node-pre-gyp ERR! Tried to download: https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.15/fse-v1.0.15-node-v46-linux-x64.tar.gz

如果其他人遇到这个问题,我的问题出在我的 .gitignore 中,我有 node_modules 而不是 node_modules/ 并且文件夹正在被跟踪和部署。从部署中删除 node_modules 文件夹解决了这个问题。

我遇到了与 fallows 类似的错误

当我查看更多详细信息部分时,我发现了这个,它是 bcrypt 库中的一个错误

所以我删除了那个库并安装了 bcryptjs 库并再次部署它,然后它就成功部署了。所以当有弃用的库和不支持的库时,可能会出现这种错误。

首先,前往

查看您的日志
  1. 转到Elastic Beanstalk.
  2. 点击您应用的环境名称
  3. Select Logs 在边栏上
  4. 单击 Request Logs 和 select Last 100 LinesFull Log.
  5. 从您的日志中,您会看到 npm 失败的原因

是时候修复它了!

  1. 如果它与gyp WARNgyp WARN EACCESSgyp ERR相关,则在项目的根目录中创建一个名为.npmrc 的文件。在此文件中,添加 unsafe-perm=true。这将强制 npm 运行 node-gyp 作为 root。

  2. 如果错误与无法安装的特定 npm 包有关,请考虑替代该包。

祝一切顺利!!