npm run dev本地項目出錯
問題棧
verbose Please try running this command again as root/Administrator.
2729 verbose stack Error: node-sass@3.13.1 postinstall:node scripts/build.js
2729 verbose stack Exit status 1
2729 verbose stack at EventEmitter.(C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:283:16)
2729 verbose stack at emitTwo (events.js:125:13)
2729 verbose stack at EventEmitter.emit (events.js:213:7)
2729 verbose stack at ChildProcess.(C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
2729 verbose stack at emitTwo (events.js:125:13)
2729 verbose stack at ChildProcess.emit (events.js:213:7)
2729 verbose stack at maybeClose (internal/child_process.js:897:16)
2729 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
- 分析發現與node-sass安裝相關,一開始以為是網絡問題,使用cnpm安裝后出現同樣問題,百度了下說要編譯下發現下面錯誤。
環境
-
OS:Win10
-
Python:2.7
-
npm -v
5.0.3 -
node -v
v8.1.3
問題復現--發現與npm rebuild node-sass 出錯相關
ERR! stack Error:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
failed with exit code: 1
stack at ChildProcess.onExit (f:\SOFTWARE\Nodejs\install4.1\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10240
查看node-gyp的安裝教程發現windows環境需要安裝Visual C++ Build Environment
下載安裝成功后需要設置使用cmd命令執行:npm config set msvs_version 2015,后面可以歡快的編譯npm rebuild node-sass了
后續--node-sass干啥子用的
node-sass是編譯sass到css文件,甚至可以通過中間件的方式自動編譯。