在nodejs项目里想安装sqlite3
输入下面代码后报错
npm install sqlite3
npm warn deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated npmlog@6.0.2: This package is no longer supported.
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated are-we-there-yet@3.0.1: This package is no longer supported.
npm warn deprecated gauge@4.0.4: This package is no longer supported.
npm error code 1
npm error path F:\bjy_docu\Internet_media\more\more\node_modules\sqlite3
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c prebuild-install -r napi || node-gyp rebuild
npm error prebuild-install warn install connect ECONNREFUSED 127.0.0.1:443
npm error gyp info it worked if it ends with ok
npm error gyp info using node-gyp@8.4.1
npm error gyp info using node@22.20.0 | win32 | x64
npm error (node:35676) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
npm error (Use `node --trace-deprecation ...` to show where the warning was created)
npm error gyp info find Python using Python version 3.13.7 found at "E:\develop\python3.13.7\python.exe"
npm error gyp info find VS using VS2019 (16.11.35931.194) found at:
npm error gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
npm error gyp info find VS run with --verbose for detailed information
npm error gyp info spawn E:\develop\python3.13.7\python.exe
npm error gyp info spawn args [
npm error gyp info spawn args 'F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '-f',
npm error gyp info spawn args 'msvs',
npm error gyp info spawn args '-I',
npm error gyp info spawn args 'F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\sqlite3\\build\\config.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args 'F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\node-gyp\\addon.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args 'C:\\Users\\bai\\AppData\\Local\\node-gyp\\Cache\\22.20.0\\include\\node\\common.gypi',
npm error gyp info spawn args '-Dlibrary=shared_library',
npm error gyp info spawn args '-Dvisibility=default',
npm error gyp info spawn args '-Dnode_root_dir=C:\\Users\\bai\\AppData\\Local\\node-gyp\\Cache\\22.20.0',
npm error gyp info spawn args '-Dnode_gyp_dir=F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\node-gyp',
npm error gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\bai\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\22.20.0\\\\<(target_arch)\\\\node.lib',
npm error gyp info spawn args '-Dmodule_root_dir=F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\sqlite3',
npm error gyp info spawn args '-Dnode_engine=v8',
npm error gyp info spawn args '--depth=.',
npm error gyp info spawn args '--no-parallel',
npm error gyp info spawn args '--generator-output',
npm error gyp info spawn args 'F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\sqlite3\\build',
npm error gyp info spawn args '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error Traceback (most recent call last):
npm error File "F:\bjy_docu\Internet_media\more\more\node_modules\node-gyp\gyp\gyp_main.py", line 42, in <module>
npm error import gyp # noqa: E402
npm error ^^^^^^^^^^
npm error File "F:\bjy_docu\Internet_media\more\more\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 9, in <module>
npm error import gyp.input
npm error File "F:\bjy_docu\Internet_media\more\more\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 19, in <module>
npm error from distutils.version import StrictVersion
npm error ModuleNotFoundError: No module named 'distutils'
npm error gyp ERR! configure error
npm error gyp ERR! stack Error: `gyp` failed with exit code: 1
npm error gyp ERR! stack at ChildProcess.onCpExit (F:\bjy_docu\Internet_media\more\more\node_modules\node-gyp\lib\configure.js:259:16)
npm error gyp ERR! stack at ChildProcess.emit (node:events:519:28)
npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm error gyp ERR! System Windows_NT 10.0.26100
npm error gyp ERR! command "E:\\develop\\Nodejs22\\node.exe" "F:\\bjy_docu\\Internet_media\\more\\more\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm error gyp ERR! cwd F:\bjy_docu\Internet_media\more\more\node_modules\sqlite3
npm error gyp ERR! node -v v22.20.0
npm error gyp ERR! node-gyp -v v8.4.1
npm error gyp ERR! not ok
npm error A complete log of this run can be found in: C:\Users\bai\AppData\Local\npm-cache\_logs\2025-10-09T08_28_41_296Z-debug-0.log
使用了网上大部分的方法没有用
最后通过下面解决
- 将Python设置到系统变量里

-
在终端使用下方代码安装
npm install sqlite3@5.1.6 --registry=https://registry.npmjs.org --verbose