安装Strapi时better-sqlite3构建失败,求助解决方法
Strapi安装失败(better-sqlite3编译错误)
问题详情
执行命令 npx create-strapi-app@latest my-project 安装Strapi时失败,此前该操作可正常运行。已尝试重装Python、Node.js、sqlite3、node-gyp,问题仍未解决。
错误日志
Creating a new Strapi application at D:\next\traversy\my-project. Creating files. error D:\next\traversy\my-project\node_modules\better-sqlite3: Command failed. Exit code: 1 Command: prebuild-install || npm run build-release Arguments: Directory: D:\next\traversy\my-project\node_modules\better-sqlite3 Output: prebuild-install warn install No prebuilt binaries found (target=18.12.1 runtime=node arch=x64 libc= platform=win32) > better-sqlite3@7.4.6 build-release > node-gyp rebuild --release gyp info it worked if it ends with ok gyp info using node-gyp@9.1.0 gyp info using node@18.12.1 | win32 | x64 gyp info find Python using Python version 3.11.0 found at "C:\Users\zayts\AppData\Local\Programs\Python\Python311\python.exe" gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details gyp ERR! find VS looking for Visual Studio 2015 gyp ERR! find VS - not found gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47) gyp ERR! stack at C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:364:14) gyp ERR! stack at C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14 gyp ERR! stack at C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:385:16 gyp ERR! stack at C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at C:\Users\zayts\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (node:child_process:420:5) gyp ERR! stack at ChildProcess.emit (node:events:513:28) gyp ERR! stack at maybeClose (node:internal/child_process:1091:16) gyp ERR! System Windows_NT 10.0.22000 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\zayts\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release" gyp ERR! cwd D:\next\traversy\my-project\node_modules\better-sqlite3 gyp ERR! node -v v18.12.1 gyp ERR! node-gyp -v v9.1.0 gyp ERR! not ok Keep trying! Oh, it seems that you encountered errors while installing dependencies in your project. Don't give up, your project was created correctly.
解决方法
- 安装Visual Studio 2017或更高版本,安装时必须勾选**「使用C++的桌面开发」**工作负载,确保包含MSVC编译器、Windows SDK等核心编译组件
- 安装完成后,以管理员身份打开Visual Studio对应的「开发者命令提示符」,在该终端中重新执行Strapi安装命令
- 若已安装Visual Studio但仍报错,手动配置npm的
msvs_version参数(替换为你的Visual Studio版本,比如2022):npm config set msvs_version 2022 --global - 建议将Python版本切换到3.7-3.10区间,虽然错误日志中识别到Python 3.11,但部分旧版node-gyp对高版本Python兼容性有限
内容的提问来源于stack exchange,提问作者Andrii Zaitsev
相关产品推荐
相关产品推荐

