关于npm安装electron和better-sqlite3失败问题

发布于:2025-08-29 ⋅ 阅读:(21) ⋅ 点赞:(0)

环境:Windows 11

npm安装electron

最近研究electron时,使用npm或者yarn安装electron时,总是安装失败。
后来在使用electron-vite构建项目时,发现构建完后,根目录下有一个文件.npmrc。配置如下:
在这里插入图片描述
如果你不是通过electron-vite构建项目,只是想通过npm或者yarn安装electron,可以在项目根目录下创建该文件,并配置上图配置,再通过npm安装,就可以顺利安装。

electron_mirror=https://npmmirror.com/mirrors/electron/
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/

npm安装better-sqlite3

安装better-sqlite3时,各种报错,提示预编译失败,缺少相关环境。报错如下:

error E:\Electron\electron-app\node_modules\better-sqlite3: Command failed.
Exit code: 1
Command: prebuild-install || node-gyp rebuild --release
Arguments:
Directory: E:\Electron\electron-app\node_modules\better-sqlite3
Output:
prebuild-install warn install Request timed out

E:\Electron\electron-app\node_modules\better-sqlite3>if not defined npm_config_node_gyp (node "D:\software\........\node-gyp.js" rebuild --release )  else (node "" rebuild --release )
gyp info it worked if it ends with ok
gyp info using node-gyp@11....
gyp info using node@22... | win32 | x64
gyp info find Python using Python version 3.13.7 found at "C:\Users\....\python.exe"

gyp http GET https://nodejs.org/download/release/v22.18.0/node-v22.18.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v22.18.0/node-v22.18.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v22.18.0/SHASUMS256.txt
gyp http GET https://nodejs.org/download/release/v22.18.0/win-x64/node.lib
gyp http 200 https://nodejs.org/download/release/v22.18.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v22.18.0/win-x64/node.lib
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
gyp ERR! find VS Failure details: undefined
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
gyp ERR! find VS Failure details: undefined
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2015 as it is only supported up to Node.js 18
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
.............
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

我按照提示安装了python,并配置环境变量后,依然报错。可能与是否安装了python并没有关系。
后来按照提示还安装了:Visual Studio 2022(这里不是vscode,安装过程中只选择C++桌面开发,这玩意儿太大了,不用装的都取消选择。)
此时再使用npm或yarn安装better-sqlite3,才安装成功。
AI还给了另一种安装方式使用预编译二进制包,未进行尝试。


网站公告

今日签到

点亮在社区的每一天
去签到