简体   繁体   English

无法使用 npm 安装 sqlite3 依赖项

[英]Can't install sqlite3 dependency with npm

I'm running Pop._OS (Ubuntu) 20.04, When I try to add sqlite3 to my dependencies on my nodejs project: I get this wall of warnings:我正在运行 Pop._OS (Ubuntu) 20.04,当我尝试将 sqlite3 添加到我的 nodejs 项目的依赖项中时:我收到这堵警告墙:

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 /home/kevinlopez/Documents/Projects/wsky-be/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 '/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
  AR(target) Release/obj.target/../node-addon-api/nothing.a
  COPY Release/nothing.a
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3320300/sqlite3.c
/bin/sh: 1: python: not found
make: *** [deps/action_before_build.target.mk:13: Release/obj/gen/sqlite-autoconf-3320300/sqlite3.c] Error 127
make: Leaving directory '/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194: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.8.0-7630-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/home/kevinlopez/Documents/Projects/wsky-be/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 /home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3
gyp ERR! node -v v14.15.4
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 '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/kevinlopez/Documents/Projects/wsky-be/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> (/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/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.8.0-7630-generic
node-pre-gyp ERR! command "/usr/bin/node" "/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/kevinlopez/Documents/Projects/wsky-be/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 '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/kevinlopez/Documents/Projects/wsky-be/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/kevinlopez/Documents/Projects/wsky-be/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 wsky-be@1.0.0 No description
npm WARN wsky-be@1.0.0 No repository field.
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!     /home/kevinlopez/.npm/_logs/2021-01-17T06_26_58_042Z-debug.log

I've tried uninstalling and reinstalling npm and nodejs, deleting and reinstalling node_modules and package-lock.json, deleting ~/.node-gyp and running npm i -g node-gyp , and installing build essentials with sudo apt-get install -y build-essential I've tried uninstalling and reinstalling npm and nodejs, deleting and reinstalling node_modules and package-lock.json, deleting ~/.node-gyp and running npm i -g node-gyp , and installing build essentials with sudo apt-get install -y build-essential

This is my package.json:这是我的 package.json:

{
  "name": "wsky-be",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "helmet": "^4.3.1",
    "knex": "^0.21.15"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  }
}

Pass the python path to the npm install proccess, that way the python will be found将 python 路径传递给 npm 安装过程,这样就可以找到 python

npm install --build-from-source --python=/usr/bin/python3

Remember to put the desired python version, don't forget that python3 is the best choice nowadays.记得放上想要的python版本,别忘了python3是现在最好的选择。 I used the path: /usr/bin/python3.8 and worked as well.我使用了路径:/usr/bin/python3.8 并且工作得很好。

found this command at: github issue at node-sqlite3 repository 在 node-sqlite3 存储库中找到此命令:github 问题

I think this issue comes from latest version of sqlite3.我认为这个问题来自最新版本的 sqlite3。 Try npm install sqlite3@4.1.1 and use it.尝试npm install sqlite3@4.1.1并使用它。 It works perfect for me它非常适合我

An alternative to symlinking python3 to python (which is what python-is-python3 does) would be setting the python variable in your npm config.将 python3 符号链接到 python(这是python-is-python3所做的)的替代方法是在 npm 配置中设置python变量。 Example: npm config set python /usr/local/bin/python3 .示例: npm config set python /usr/local/bin/python3

splite3 uses python 2.7 to build. splite3 使用 python 2.7 构建。 Had the same problem.有同样的问题。 I had to set the path to python in the npm config.我必须在 npm 配置中设置 python 的路径。 For me (on Linux) the solution was: npm config set python /usr/bin/python2对我来说(在 Linux 上),解决方案是: npm config set python /usr/bin/python2

Then I was able to install sqlite3 successfully.然后我能够成功安装 sqlite3。

And transferring comment to answer:并转移评论以回答:

I suggest you install python (make it available), given the message /bin/sh: 1: python: not found .我建议您安装 python (使其可用),给出消息/bin/sh: 1: python: not found

do npm uninstall node-pre-gyp --save npm install @mapbox/node-pre-gyp --save npm install sqlite3执行npm uninstall node-pre-gyp --save npm install @mapbox/node-pre-gyp --save npm install sqlite3

the above solved my issue.以上解决了我的问题。

For anyone having this problem.对于任何有这个问题的人。 I'm working with my Office PC where everything is restricted, therefore install this sqlite3 returns error as it requires compilation during npm install.我正在使用我的 Office PC,一切都受到限制,因此安装此 sqlite3 会返回错误,因为它需要在 npm 安装期间进行编译。 Here's what I'm figure out:这是我想出的:

    1. If my package.json has only "sqlite3": "^5.0.2" (no any other lib) then npm install works.如果我的 package.json 只有"sqlite3": "^5.0.2" (没有任何其他库),那么npm install有效。 But if I add all other libs that needs for my project + sqlite@5.0.2, remove nodes_modules, run npm install again, then it'll fail ->> solution for this is adding only "sqlite3": "^5.0.2" and run npm install first, then manually add other dependencies later and run npm install one more time, of course this is not a preferred way as we need to manually do但是,如果我添加我的项目所需的所有其他库 + sqlite@5.0.2,删除节点模块,再次运行npm install ,那么它会失败 ->> 解决方案是只添加"sqlite3": "^5.0.2"并首先运行npm install ,然后手动添加其他依赖项并再次运行npm install ,当然这不是首选方式,因为我们需要手动执行
    1. downgrage to "sqlite3": "^4.1.1" fixed the problem, I can define sqlite3 with all other libs in my package.json -->> I'm going with this approach downgrage to "sqlite3": "^4.1.1"解决了这个问题,我可以用我的 package.json 中的所有其他库定义sqlite3 -->> 我将采用这种方法

I also tried for hours to overcome the same setback but I solved it in 2 simple steps:我也尝试了几个小时来克服同样的挫折,但我通过两个简单的步骤解决了它:

  1. npm rebuild

  2. npm i sqlite

It worked for me!它对我有用!

added version "sqlite3": "^4.1.1" in package.json and ran command在 package.json 中添加版本"sqlite3": "^4.1.1"并运行命令

npm install --build-from-source --python=/usr/bin/python3

resolved the issue for me为我解决了这个问题

Edit on 2022: Mostly its not on python but the supported version of node 2022 年编辑:主要不在 python 上,而是在受支持的节点版本上

Please check the supported version of Node in sqlite npm documentation and use the supported Node version (mostly by downgrading using nvm)请查看 sqlite npm 文档中支持的 Node 版本并使用支持的 Node 版本(主要是通过使用 nvm 降级)

For me the node verion is v16.x whereas the Sqlite max supported version is v12.x, so I downgraded and the issues went off!对我来说,节点版本是 v16.x,而 Sqlite 最大支持版本是 v12.x,所以我降级了,问题就解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM