执行npm install失败求助:node-sass@4.9.0跨平台安装报错
npm install Failures with node-sass@4.9.0 on Node.js v12.13.0 Hey there! Let's get your npm install working smoothly. First, let's split out the harmless warnings from the actual error that's stopping your setup:
Harmless Warnings (You Can Totally Ignore These)
No license field: This is just a heads-up that your project'spackage.jsondoesn't have alicenseproperty defined. It won't block your install—if you want to fix it later, add something like"license": "MIT"to yourpackage.jsonfile.- fsevents skipped warnings: fsevents is a macOS-only tool for file system watching. Since you're working on Windows (and tested other OSes too), npm correctly skips installing it. No action needed here at all.
The Real Problem: node-sass@4.9.0 and Node.js v12.13.0 Don't Play Nice
The critical error breaking your install is:
Failed at the node-sass@4.9.0 postinstall script
node-sass has strict version compatibility rules with Node.js. node-sass@4.9.0 doesn't support Node.js v12.x—it only works with Node.js v8.x and v10.x. Since you're running Node v12.13.0, the postinstall build script fails every time.
Solutions to Fix This
Pick one of these approaches based on your project's needs:
1. Upgrade node-sass to a Version That Supports Node v12
node-sass@4.12.0 and newer versions work with Node.js v12. Here's how to update:
- First, wipe your existing dependencies and lock file:
- On Windows:
rmdir /s node_modules del package-lock.json - On macOS/Linux:
rm -rf node_modules package-lock.json
- On Windows:
- Install the compatible node-sass version:
npm install node-sass@^4.12.0 --save-dev - Finally, run
npm installagain.
2. Downgrade Node.js to a Version Supported by node-sass@4.9.0
If your project relies on node-sass@4.9.0 (due to other dependency constraints), you'll need to switch to Node.js v10.x (the latest version that works with node-sass@4.9.0). Use Node Version Manager (nvm) to make this easy:
- Install nvm (use
nvm-windowsfor Windows, official nvm for macOS/Linux) - Install Node v10:
nvm install 10 - Switch to Node v10:
nvm use 10 - Now run
npm installagain—it should work.
3. (Windows Only) Install Build Tools If You Still Hit Errors
If version fixes don't resolve the build issue, Windows might need extra tools for node-sass to compile. Install them globally with:
npm install --global windows-build-tools
Restart your terminal after installation, then run npm install once more.
内容的提问来源于stack exchange,提问作者Ashkan Pirmani

