在Elastic Beanstalk上安装公共npm模块的分叉时出错



我在部署一个应用程序时遇到了问题,该应用程序使用了托管在Github上的公共NPM模块的稍微修改过的版本。我分叉回购并进行更改,然后提交并成功安装。该模块在开发和运行生产构建时都在本地工作。

问题是当我使用eb deploy <environment name>将应用程序部署到Elastic Beanstalk时。我知道这个模块有问题,因为如果我从package.json中删除它,我就可以成功部署它。

请参阅以下错误日志:

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/.npm/_logs/2020-04-02T12_28_43_807Z-debug.log
Running npm install:  /opt/elasticbeanstalk/node-install/node-v12.16.1-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
UTC 2020/04/02 12:28:50 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log 
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-v12.16.1-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1 (ElasticBeanstalk::ExternalInvocationError)
caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm ERR! prepareGitDep 1> 
npm ERR! prepareGitDep > deasync@0.1.15 install /tmp/.npm/_cacache/tmp/git-clone-f83c32d6/node_modules/deasync
npm ERR! prepareGitDep > node ./build.js
npm ERR! prepareGitDep 
npm ERR! prepareGitDep `linux-x64-node-12` exists; testing
npm ERR! prepareGitDep Binary is fine; exiting
npm ERR! prepareGitDep 
npm ERR! prepareGitDep > pre-commit@1.2.2 install /tmp/.npm/_cacache/tmp/git-clone-f83c32d6/node_modules/pre-commit
npm ERR! prepareGitDep > node install.js
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 
npm ERR! prepareGitDep 2> npm WARN install Usage of the `--dev` option is deprecated. Use `--only=dev` instead.
npm ERR! prepareGitDep internal/fs/utils.js:230
npm ERR! prepareGitDep     throw err;
npm ERR! prepareGitDep     ^
npm ERR! prepareGitDep 
npm ERR! prepareGitDep Error: EACCES: permission denied, mkdir '/tmp/.npm/_cacache/tmp/git-clone-f83c32d6/.git/hooks'
npm ERR! prepareGitDep     at Object.mkdirSync (fs.js:840:3)
npm ERR! prepareGitDep     at Object.<anonymous> (/tmp/.npm/_cacache/tmp/git-clone-f83c32d6/node_modules/pre-commit/install.js:28:24)
npm ERR! prepareGitDep     at Module._compile (internal/modules/cjs/loader.js:1158:30)
npm ERR! prepareGitDep     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
npm ERR! prepareGitDep     at Module.load (internal/modules/cjs/loader.js:1002:32)
npm ERR! prepareGitDep     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
npm ERR! prepareGitDep     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
npm ERR! prepareGitDep     at internal/main/run_main_module.js:18:47 {
npm ERR! prepareGitDep   errno: -13,
npm ERR! prepareGitDep   syscall: 'mkdir',
npm ERR! prepareGitDep   code: 'EACCES',
npm ERR! prepareGitDep   path: '/tmp/.npm/_cacache/tmp/git-clone-f83c32d6/.git/hooks'
npm ERR! prepareGitDep }
npm ERR! prepareGitDep npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm ERR! prepareGitDep npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! code ELIFECYCLE
npm ERR! prepareGitDep npm ERR! errno 1
npm ERR! prepareGitDep npm ERR! pre-commit@1.2.2 install: `node install.js`
npm ERR! prepareGitDep npm ERR! Exit status 1
npm ERR! prepareGitDep npm ERR! 
npm ERR! prepareGitDep npm ERR! Failed at the pre-commit@1.2.2 install script.
npm ERR! prepareGitDep npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! prepareGitDep 
npm ERR! prepareGitDep npm ERR! A complete log of this run can be found in:
npm ERR! prepareGitDep npm ERR!     /tmp/.npm/_logs/2020-04-02T12_28_43_507Z-debug.log
npm ERR! prepareGitDep 
npm ERR! premature close
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/.npm/_logs/2020-04-02T12_28_43_807Z-debug.log
Running npm install:  /opt/elasticbeanstalk/node-install/node-v12.16.1-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
UTC 2020/04/02 12:28:50 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log 
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-v12.16.1-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1 (Executor::NonZeroExitStatus)

值得一提的是,我之前已经用unsafe-perm=true创建了一个.npmrc文件,所以EB作为根用户运行npm install

对于任何遇到这个问题的人,我通过直接将模块中的构建文件复制到我自己的项目中并在package.json中安装任何必要的依赖项来解决这个问题。

最新更新