无法安装sqlite3作为对AWS的依赖

问题描述

我创建了一个应用程序,其中使用sqlite来存储数据。它在本地运行良好,我尝试在AWS上部署节点应用程序,但是无法安装sqlite3软件包,我不知道为什么。

eb-engine日志

----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2020/09/15 18:27:56.475030 [INFO] Downloading: bucket: elasticbeanstalk-eu-west-1-517303674880,object: /resources/environments/e-fdemiazfan/_runtime/versions/manifest_1600194473607
2020/09/15 18:27:56.537203 [INFO] Download successful158bytes downloaded
2020/09/15 18:27:56.537358 [INFO] Trying to read and parse version manifest...
2020/09/15 18:27:56.537432 [INFO] Downloading: bucket: elasticbeanstalk-eu-west-1-517303674880,object: /resources/environments/e-fdemiazfan/_runtime/_versions/llaimagames-backend/code-pipeline-1600194468852-6f5ca48cf59015e5287229cc2aa09408bb1cf111
2020/09/15 18:27:56.547941 [INFO] Download successful10287bytes downloaded
2020/09/15 18:27:56.548121 [INFO] Executing instruction: Electleader
2020/09/15 18:27:56.548135 [INFO] Running leader election for instance i-0fbd2ec436aa6952a...
2020/09/15 18:27:56.548139 [INFO] Calling the cfn-elect-cmd-leader to elect the command leader.
2020/09/15 18:27:56.548155 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-elect-cmd-leader --stack arn:aws:cloudformation:eu-west-1:517303674880:stack/awseb-e-fdemiazfan-stack/fd62a1f0-f68e-11ea-bd15-0a9bdcf5c20a --command-name ElasticBeanstalkCommand-AWSEBAutoScalingGroup --invocation-id ef591c3d-43c6-4082-aabe-2aeacff9aec6 --listener-id i-0fbd2ec436aa6952a --region eu-west-1
2020/09/15 18:27:56.894802 [INFO] Instance is leader.
2020/09/15 18:27:56.894847 [INFO] Executing instruction: stopSqsd
2020/09/15 18:27:56.894852 [INFO] This is a web server environment instance,skip stop sqsd daemon ...
2020/09/15 18:27:56.894857 [INFO] Executing instruction: PreBuildEbExtension
2020/09/15 18:27:56.894876 [INFO] Starting executing the config set Infra-EmbeddedPreBuild.
2020/09/15 18:27:56.894899 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-init -s arn:aws:cloudformation:eu-west-1:517303674880:stack/awseb-e-fdemiazfan-stack/fd62a1f0-f68e-11ea-bd15-0a9bdcf5c20a -r AWSEBAutoScalingGroup --region eu-west-1 --configsets Infra-EmbeddedPreBuild
2020/09/15 18:27:57.259401 [INFO] Finished executing the config set Infra-EmbeddedPreBuild.

2020/09/15 18:27:57.259424 [INFO] Executing instruction: StageApplication
2020/09/15 18:27:57.259825 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2020/09/15 18:27:57.259850 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2020/09/15 18:27:57.262669 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2020/09/15 18:27:57.263178 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/09/15 18:27:57.263196 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2020/09/15 18:27:57.263201 [INFO] Executing instruction: Install customer specified node.js version
2020/09/15 18:27:57.263205 [INFO] installing specified nodejs version...
2020/09/15 18:27:57.263272 [INFO] there is no nodejs version specified in package.json,skip installing specified version of nodejs
2020/09/15 18:27:57.263281 [INFO] Executing instruction: Use NPM to install dependencies
2020/09/15 18:27:57.263291 [INFO] use npm to install dependencies
2020/09/15 18:27:57.263320 [INFO] Running command /bin/sh -c npm config set jobs 1
2020/09/15 18:27:57.496763 [INFO] Running command /bin/sh -c npm --production install
2020/09/15 18:28:03.895258 [INFO] 
> sqlite3@5.0.0 install /var/app/staging/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

Failed to execute '/opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/bin/node /opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)

2020/09/15 18:28:03.895293 [ERROR] An error occurred during execution of command [app-deploy] - [Use NPM to install dependencies]. Stop running the command. Error: Command /bin/sh -c npm --production install Failed with error exit status 1. Stderr:npm WARN deprecated crypto@1.0.1: This package is no longer supported. It's Now a built-in Node module. If you've depended on crypto,you should switch to the one that's built-in.
npm WARN deprecated request@2.88.2: request has been deprecated,see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Pre-built binaries not installable for sqlite3@5.0.0 and node@12.18.3 (node-v72 ABI,glibc) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error EACCES: permission denied,mkdir '/var/app/staging/node_modules/sqlite3/lib/binding' 
gyp WARN EACCES current user ("healthd") does not have permission to access the dev dir "/root/.cache/node-gyp/12.18.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/var/app/staging/node_modules/sqlite3/.node-gyp"
gyp WARN install got an error,rolling back install
gyp WARN install got an error,rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied,mkdir '/var/app/staging/node_modules/sqlite3/.node-gyp'
gyp ERR! System Linux 4.14.192-147.314.amzn2.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
gyp ERR! cwd /var/app/staging/node_modules/sqlite3
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/bin/node /opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/var/app/staging/node_modules/sqlite3/lib/binding/napi-v3-linux-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/var/app/staging/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Linux 4.14.192-147.314.amzn2.x86_64
node-pre-gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v12.18.3-linux-x64/bin/node" "/var/app/staging/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /var/app/staging/node_modules/sqlite3
node-pre-gyp ERR! node -v v12.18.3
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok 
npm WARN backend@2.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@5.0.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sqlite3@5.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-09-15T18_28_03_882Z-debug.log
 

2020/09/15 18:28:03.895312 [INFO] Executing cleanup logic
2020/09/15 18:28:03.895406 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment: You didn't specify a Node.js version in the 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version.","timestamp":1600194477,"severity":"INFO"},{"msg":"Instance deployment: 'npm' Failed to install dependencies that you defined in 'package.json'. For details,see 'eb-engine.log'. The deployment Failed.","timestamp":1600194483,"severity":"ERROR"},{"msg":"Instance deployment Failed. For details,see 'eb-engine.log'.","severity":"ERROR"}]}]}

2020/09/15 18:28:03.895555 [INFO] Platform Engine finished execution on command: app-deploy

2020/09/15 18:28:50.916583 [INFO] Starting...
2020/09/15 18:28:50.916625 [INFO] Starting EBPlatform-PlatformEngine
2020/09/15 18:28:50.916640 [INFO] reading event message file
2020/09/15 18:28:50.916736 [INFO] no eb envtier info file found,skip loading env tier info.
2020/09/15 18:28:50.916805 [INFO] Engine received EB command cfn-hup-exec

2020/09/15 18:28:50.990909 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-Metadata -s arn:aws:cloudformation:eu-west-1:517303674880:stack/awseb-e-fdemiazfan-stack/fd62a1f0-f68e-11ea-bd15-0a9bdcf5c20a -r AWSEBAutoScalingGroup --region eu-west-1
2020/09/15 18:28:51.300432 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-Metadata -s arn:aws:cloudformation:eu-west-1:517303674880:stack/awseb-e-fdemiazfan-stack/fd62a1f0-f68e-11ea-bd15-0a9bdcf5c20a -r AWSEBBeanstalkMetadata --region eu-west-1
2020/09/15 18:28:51.593864 [INFO] checking whether command tail-log is applicable to this instance...
2020/09/15 18:28:51.593877 [INFO] this command is applicable to the instance,thus instance should execute command
2020/09/15 18:28:51.593881 [INFO] Engine command: (tail-log)

2020/09/15 18:28:51.593928 [INFO] Executing instruction: GetTailLogs
2020/09/15 18:28:51.593933 [INFO] Tail Logs...
2020/09/15 18:28:51.594172 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log

Package.json

{
  "name": "backend","version": "2.0.0","description": "","main": "server.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",},"author": "","license": "ISC","dependencies": {
    "body-parser": "^1.19.0","crypto": "^1.0.1","express": "^4.17.1","MysqL": "^2.18.1","sqlite3": "^5.0.0"
  }
}

解决方法

gyp ERR! stack Error: EACCES: permission denied,mkdir '/var/app/staging/node_modules/sqlite3/.node-gyp' gyp ERR! System Linux 4.14.192-147.314.amzn2.x86_64

可能重复的问题here 尝试将.npmrcunsafe-perm=true

相加