在 VPS 上安装依赖项时出现 SQLite 问题

问题描述

我正在尝试将用 TypeScript 开发的 discord 机器人托管到我从 galaxygate 拥有的 VPS 中,该 VPS 与 Ubuntu 20.04 一起运行。

Git 已经安装,所以我克隆并拉出了我在 GitHub 上托管的项目。然后我尝试npm install我的依赖项。

以下是 package.json 中的依赖项:

{
  "devDependencies": {
    "@types/node": "^14.14.22","@types/ws": "^7.4.0","rimraf": "^3.0.2","ts-node-dev": "^1.1.1","tsconfig-paths": "^3.9.0","typescript": "^4.1.3"
  },"dependencies": {
    "consola": "^2.15.0","discord-akairo": "^8.1.0","discord.js": "github:discordjs/discord.js","dotenv": "^8.2.0","sqlite3": "^5.0.1","ts-node": "^9.1.1","typeorm": "^0.2.30"
  }
}

当我安装依赖项时出现了一些错误,因此通过 nvm 我将节点版本设置为适合 sqlite3 的节点版本:

  • node -v => v14.15.4
  • npm -v => 6.14.10

这是npm i的踪迹:

> sqlite3@5.0.1 install /root/Main/Perceval/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapBox-node-binary.s3.amazonaws.com/sqlite3/v5.0.1/napi-v6-linux-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@5.0.1 and node@14.15.4 (node-v83 ABI,glibc) (falling back to source compile with node-gyp)
make: Entering directory '/root/Main/Perceval/node_modules/sqlite3/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
make: cc: Command not found
make: *** [../node-addon-api/nothing.target.mk:107: Release/obj.target/nothing/../node-addon-api/nothing.o] Error 127
make: Leaving directory '/root/Main/Perceval/node_modules/sqlite3/build'
gyp ERR! build error
gyp ERR! stack Error: `make` Failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/Main/Perceval/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Linux 5.4.0-42-generic
gyp ERR! command "/root/.nvm/versions/node/v14.15.4/bin/node" "/root/Main/Perceval/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6"
gyp ERR! cwd /root/Main/Perceval/node_modules/sqlite3
gyp ERR! node -v v14.15.4
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/root/.nvm/versions/node/v14.15.4/bin/node /root/Main/Perceval/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/root/Main/Perceval/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:1048:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
node-pre-gyp ERR! System Linux 5.4.0-42-generic
node-pre-gyp ERR! command "/root/.nvm/versions/node/v14.15.4/bin/node" "/root/Main/Perceval/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /root/Main/Perceval/node_modules/sqlite3
node-pre-gyp ERR! node -v v14.15.4
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
Failed to execute '/root/.nvm/versions/node/v14.15.4/bin/node /root/Main/Perceval/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/root/Main/Perceval/node_modules/sqlite3/lib/binding/napi-v6-linux-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.1 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@5.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@5.0.1 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/2021-02-05T15_36_09_631Z-debug.log

这里是nmp i -D sqlite3

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

> sqlite3@5.0.1 install /root/Main/Perceval/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapBox-node-binary.s3.amazonaws.com/sqlite3/v5.0.1/napi-v6-linux-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@5.0.1 and node@14.15.4 (node-v83 ABI,"arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@5.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@5.0.1 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/2021-02-05T15_37_32_352Z-debug.log

解决方法

错误不在python中,而是在sqlite3包本身中。

恢复到 v5.0.0 将解决这个问题

npm install sqlite3@5.0.0