Node.js npm安装URSA失败,已尝试相关方案仍无法解决
Hey there, I feel your pain—node-gyp-related install errors can be a total headache, especially when standard fixes don’t pan out. Let’s walk through some targeted steps to get ursa installed properly, based on your Windows setup and the error snippet you shared:
C:\Users\Journey\Desktop\Encrypt\node_modules\ursa>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" r...
Step 1: Verify Node-GYP’s Windows Dependencies Are Fully Configured
Ursa relies on node-gyp, which has strict requirements for Windows. Double-check these:
- Python 2.7: Node-gyp still requires Python 2.7 (not 3.x). Install it, then set it in npm config with:
npm config set python "C:\Path\To\Python27\python.exe" - Visual Studio Build Tools: Install the Desktop Development with C++ workload for Visual Studio 2019 or 2022. If you don’t want full VS, use the standalone build tools:
npm install --global --production windows-build-tools - Set MSVS Version: Match your installed VS version in npm config (e.g., for 2019):
npm config set msvs_version 2019
Step 2: Clean Slate Install
Corrupted cache or partial installs often cause issues. Try this:
- Delete your
node_modulesfolder andpackage-lock.json:rd /s /q node_modules del package-lock.json - Clear npm’s cache:
npm cache clean --force - Try installing a specific, stable version of ursa (the latest may be incompatible with newer Node.js):
npm install --save ursa@0.9.4
Step 3: Check Node.js Version Compatibility
Ursa hasn’t been updated in years, so it may break with modern Node.js versions (16+). Use Node Version Manager (nvm) to switch to a compatible version like 14.x:
- Install nvm for Windows, then run:
nvm install 14.21.3 nvm use 14.21.3 - Retry the ursa install.
Step 4: Manual Node-GYP Rebuild
If the install still fails, get more detailed error info by rebuilding manually:
- Install node-gyp globally:
npm install -g node-gyp - Navigate to the ursa folder (if the install partially completed):
cd node_modules/ursa - Run the rebuild command directly:
node-gyp rebuild
This will show the exact failure reason (e.g., missing OpenSSL libraries, version mismatches) which you can use to troubleshoot further.
Alternative: Switch to a Maintained Library
Since ursa is no longer actively maintained, consider using Node.js’s built-in crypto module (it supports all RSA operations you’d need) or a modern alternative like node-rsa. These avoid node-gyp entirely and are more reliable long-term.
内容的提问来源于stack exchange,提问作者Kenny Rodriguez

