node-sass安裝失敗解決方法總結(jié)(終有一款適合你)
前言
項目中常常遇到node-sass安裝失敗,動不動就是報各種錯誤。以前我一次也沒有失敗過,自從系統(tǒng)重裝我的天呀,node-sass就沒有成功過,我能做的node卸載,sass重裝各種版,以及換了淘寶鏡像和用了vpn都安裝失敗。我也是無語,今天沒事特意搜搜了看,一次復制了別人的文章進行總結(jié),可以嘗試一下,應該是可以的。
(這個是我在react項目中直接解決的 node-sass方法
http://www.dbjr.com.cn/article/268609.htm
這個是我的解決react項目中node-sass博客地址.不過我覺得可能有更好的方案。)
好了廢話不多說哦,總有一款適合你。
我遇到的問題一:
npm install 時偶爾遇到報錯:沒有安裝python或node-sass 安裝失敗的問題。
百度之后發(fā)現(xiàn)是被墻了,但根據(jù)百度的方法換了淘寶鏡像和用了vpn都安裝失敗,最后發(fā)現(xiàn)原來是因為沒有卸載之前安裝失敗的包導致的。文中給出了兩種報錯問題,使用淘寶鏡像或者使用yarn,找不到當前環(huán)境的綁定可以刪除重跑。
node-sass 安裝失敗的原因
npm 安裝 node-sass 依賴時,會從 github.com 上下載 .node 文件。由于國內(nèi)網(wǎng)絡環(huán)境的問題,這個下載時間可能會很長,甚至導致超時失敗。
這是使用 sass 的同學可能都會遇到的郁悶的問題。
解決方案就是使用其他源,或者使用工具下載,然后將安裝源指定到本地。
解決方法一:使用淘寶鏡像源(推薦)
設置變量 sass_binary_site,指向淘寶鏡像地址。示例:
執(zhí)行命令
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ // 也可以設置系統(tǒng)環(huán)境變量的方式。示例 // linux、mac 下 SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass // window 下 set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ && npm install node-sass
或者設置全局鏡像源:
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ npm install node-sass
之后再涉及到 node-sass 的安裝時就會從淘寶鏡像下載。
解決方法二:使用 cnpm
使用 cnpm 安裝 node-sass 會默認從淘寶鏡像源下載,也是一個辦法:
執(zhí)行命令
cnpm install node-sass
解決方法三:創(chuàng)建.npmrc文件
在項目根目錄創(chuàng)建.npmrc文件,復制下面代碼到該文件。
phantomjs_cdnurl=http://cnpmjs.org/downloads sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ registry=https://registry.npm.taobao.org
保存后 刪除之前安裝失敗的包(第一次安裝請?zhí)^此步) 執(zhí)行命令
npm uninstall node-sass
重新安裝
npm install node-sass
解決方法四:下載 .node 到本地
(在國內(nèi)使用gulp編譯sass時,需要安裝gulp-sass,而gulp-sass依賴node-sass.
node-sass安裝需要.node文件,國內(nèi)由于各種原因無法下載)
方法 :
1、使用命令行安裝node-sass,提升安裝失敗:Cannot download
2、 嘗試使用瀏覽器下載上面提到的地址。
命令行下載方式與瀏覽器下載方式不同。瀏覽器可能可以正常下載
3、下載完成后復制文件到指定目錄(目錄不要有空格、中文)。
如復制到E盤根目錄下
4、回到命令行安裝界面。
設置SASS_BINARY_PATH環(huán)境變量 set SASS_BINARY_PATH=E:/win32-x64-46_binding.node 文件名根據(jù)自己下載的文件自行修改
然后再次安裝,可以看到我們安裝成功了
5、node-sass安裝時,查看需要的.node文件是否存在。
如果存在就不下載,如果不存在,需要下載。
我們已經(jīng)告訴node-sass文件已經(jīng)下載下來了,就在E盤,你去哪里找,他一看確實有,直接使用不再下載。
6、當然你可以直接這樣做
去根據(jù)版本號、系統(tǒng)環(huán)境,選擇下載 .node 文件,然后安裝時,指定變量 sass_binary_path
npm i node-sass --sass_binary_path=/Users/lzwme/Downloads/darwin-x64-48_binding.node
安裝失敗后重新安裝問題
之前安裝失敗,再安裝就不去下載了,怎么辦呢?那就先卸載再安裝:
npm uninstall node-sass npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
問題:[npm install 報node-sass錯誤]
npm WARN Error: EPERM: operation not permitted, scandir 'E:\zkh360\Zkh360.Web.Admin\app\node_modules\har-validator\node_modules' npm WARN { Error: EPERM: operation not permitted, scandir 'E:\zkh360\Zkh360.Web.Admin\app\node_modules\har-validator\node_modules' npm WARN stack: 'Error: EPERM: operation not permitted, scandir \'E:\\zkh360\\Zkh360.Web.Admin\\app\\node_modules\\har-validator\\node_modules\'', npm WARN errno: -4048, npm WARN code: 'EPERM', npm WARN syscall: 'scandir', npm WARN path: 'E:\\zkh360\\Zkh360.Web.Admin\\app\\node_modules\\har-validator\\node_modules' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@3.13.1 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 大致意思就是EPERM:不允許操作,scandir, node-sass@3.13.1 postinstall腳本失敗。 這可能不是npm的問題。上面可能還有其他日志輸出。
問題:Node Sass找不到當前環(huán)境的綁定
Node Sass could not find a binding for your current environment
ERROR in Missing binding /Users/warren/Sites/random-docs/ my-cms/node_modules/node-sass/vendor/darwin-x64-11/binding.node Node Sass could not find a binding for your current environment: OS X 64-bit with Node 0.10.x
解決方案。
刪除node_modules并運行npm install然后npm rebuild node-sass 什么都不做。
stackoverflow原文
如果這個 .node 還不能解決用這個方法。直接搞定。
1 查看版本號
node -p "[process.platform, process.arch, process.versions.modules].join('-')"
配置 變量 sass_binary_path:npm 命令或者yarn命令
npm config set sass-binary-path e:/web/win32-x64-93_binding.node yarn config set sass-binary-path e:/web/win32-x64-93_binding.node
解決方法五:使用梯子 來源
假設你的梯子在你本地機器上開啟了一個第三方服務器 127.0.0.1:8080,那么只需按照下面的方法配置一下就能正常安裝 node-sass 了(如果你開啟的是 PAC 模式而不是全局模式,那還需要將 s3.amazonaws.com 加入 PAC 列表):
npm config set proxy http://127.0.0.1:8080 npm i node-sass 下載完成后刪除 http 代理 npm config delete proxy
我遇到的問題二
開始的時候引入別人的一個項目 咱們一般都是執(zhí)行命令 npm install,或者 yarn命令會自動下載node-modules包 npm run dev 或者要yarn start 啟動項目 但是往往就在安裝包的時候就報錯了,各種各樣的,解決一個來一個,把管理員權(quán)限配置 了還不行,有的還說是版本的問題,改了package.json文件還不行。 > node build/dev-server.js Listening at http://localhost:8888 webpack: wait until bundle finished: /index.html webpack built 5301489d16ee90d86896 in 3165ms Hash: 5301489d16ee90d86896 Version: webpack 1.15.0 Time: 3165ms Asset Size Chunks Chunk Names app.js 1.96 MB 0 app ERROR in Cannot find module 'node-sass' @ ./src/common/scss/index.scss 4:14-124 13:2-17:4 14:20-130 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-e0c3a2e6!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/App.vue 4:14-240 13:2-17:4 14:20-246 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-690f3aee&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/ratings/ratings.vue 4:14-280 13:2-17:4 14:20-286 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-2ac60e2e&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/goods/goods.vue 4:14-278 13:2-17:4 14:20-284 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-17cac44c&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/seller/seller.vue 4:14-279 13:2-17:4 14:20-285 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-108aa294&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/split/split.vue 4:14-278 13:2-17:4 14:20-284 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-13f047fa&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/star/star.vue 4:14-277 13:2-17:4 14:20-283 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-bbdb154c&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/ratingselect/ratingselect.vue 4:14-285 13:2-17:4 14:20-291 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-652a5408&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/cartcontrol/cartcontrol.vue 4:14-284 13:2-17:4 14:20-290 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-1728dbcc&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/header/header.vue 4:14-279 13:2-17:4 14:20-285 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-40efc97a&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/shopcart/shopcart.vue 4:14-281 13:2-17:4 14:20-287 ERROR in Cannot find module 'node-sass' @ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-rewriter.js?id=data-v-617e6f7a&scoped=true!./~/sass-loader!./~/vue-loader/lib/selector.js?type=styles&index=0!./src/components/food/food.vue 4:14-277 13:2-17:4 14:20-283 Child html-webpack-plugin for "index.html": Asset Size Chunks Chunk Names index.html 1.47 MB 0 webpack: Failed to compile.
npm i node-sass -s安裝
報錯信息
E:\kibana>npm install node-sass > node-sass@3.8.0 install E:\kibana\node_modules\node-sass > node scripts/install.js Cannot download "https://github.com/sass/node-sass/releases/download/v3.8.0/win3 2-x64-48_binding.node": tunneling socket could not be established, cause=socket hang up Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 > node-sass@3.8.0 postinstall E:\kibana\node_modules\node-sass > node scripts/build.js Building: D:\Program Files\nodejs\node.exe E:\kibana\node_modules\node-gyp\bin\n ode-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ 'D:\\Program Files\\nodejs\\node.exe', gyp verb cli 'E:\\kibana\\node_modules\\node-gyp\\bin\\node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' ] gyp info using node-gyp@3.6.0 gyp info using node@6.2.0 | win32 | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2 gyp verb `which` failed at getNotFoundError (E:\kibana\node_modules\which\wh ich.js:13:12) gyp verb `which` failed at F (E:\kibana\node_modules\which\which.js:68:19) gyp verb `which` failed at E (E:\kibana\node_modules\which\which.js:80:29) gyp verb `which` failed at E:\kibana\node_modules\which\which.js:89:16 gyp verb `which` failed at E:\kibana\node_modules\isexe\index.js:42:5 gyp verb `which` failed at E:\kibana\node_modules\isexe\windows.js:36:5 gyp verb `which` failed at FSReqWrap.oncomplete (fs.js:117:15) gyp verb `which` failed python2 { Error: not found: python2 gyp verb `which` failed at getNotFoundError (E:\kibana\node_modules\which\wh ich.js:13:12) gyp verb `which` failed at F (E:\kibana\node_modules\which\which.js:68:19) gyp verb `which` failed at E (E:\kibana\node_modules\which\which.js:80:29) gyp verb `which` failed at E:\kibana\node_modules\which\which.js:89:16 gyp verb `which` failed at E:\kibana\node_modules\isexe\index.js:42:5 gyp verb `which` failed at E:\kibana\node_modules\isexe\windows.js:36:5 gyp verb `which` failed at FSReqWrap.oncomplete (fs.js:117:15) code: 'ENOENT ' } gyp verb check python checking for Python executable "python" in the PATH gyp verb `which` succeeded python C:\Python27\python.EXE gyp verb check python version `C:\Python27\python.EXE -c "import platform; print (platform.python_version());"` returned: "2.7.12\r\n" gyp verb get node dir no --target version specified, falling back to host node v ersion: 6.2.0 gyp verb command install [ '6.2.0' ] gyp verb install input version string "6.2.0" gyp verb install installing version: 6.2.0 gyp verb install --ensure was passed, so won't reinstall if already installed gyp verb install version is already installed, need to check "installVersion" gyp verb got "installVersion" 9 gyp verb needs "installVersion" 9 gyp verb install version is good gyp verb get node dir target node version installed: 6.2.0 gyp verb build dir attempting to create "build" dir: E:\kibana\node_modules\node -sass\build gyp verb build dir "build" dir needed to be created? E:\kibana\node_modules\node -sass\build gyp verb Not using VS2017: Could not use PowerShell to find VS2017 gyp verb build/config.gypi creating config file gyp verb build/config.gypi writing out config file: E:\kibana\node_modules\node- sass\build\config.gypi gyp verb config.gypi checking for gypi file: E:\kibana\node_modules\node-sass\co nfig.gypi gyp verb common.gypi checking for gypi file: E:\kibana\node_modules\node-sass\co mmon.gypi gyp verb gyp gyp format was not specified; forcing "msvs" gyp info spawn C:\Python27\python.EXE gyp info spawn args [ 'E:\\kibana\\node_modules\\node-gyp\\gyp\\gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'msvs', gyp info spawn args '-G', gyp info spawn args 'msvs_version=auto', gyp info spawn args '-I', gyp info spawn args 'E:\\kibana\\node_modules\\node-sass\\build\\config.gypi', gyp info spawn args '-I', gyp info spawn args 'E:\\kibana\\node_modules\\node-gyp\\addon.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\\Users\\15061857\\.node-gyp\\6.2.0\\include\\node\\com mon.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=C:\\Users\\15061857\\.node-gyp\\6.2.0', gyp info spawn args '-Dnode_gyp_dir=E:\\kibana\\node_modules\\node-gyp', gyp info spawn args '-Dnode_lib_file=node.lib', gyp info spawn args '-Dmodule_root_dir=E:\\kibana\\node_modules\\node-sass', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'E:\\kibana\\node_modules\\node-sass\\build', gyp info spawn args '-Goutput_dir=.' ] gyp verb command build [] gyp verb build type Release gyp verb architecture x64 gyp verb node dev dir C:\Users\15061857\.node-gyp\6.2.0 gyp verb found first Solution file build/binding.sln gyp verb could not find "msbuild.exe" in PATH - finding location in registry gyp verb "Release" dir needed to be created? null gyp verb copying "node.lib" for x64 C:\Users\15061857\.node-gyp\6.2.0\Release\no de.lib gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe gyp info spawn args [ 'build/binding.sln', gyp info spawn args '/nologo', gyp info spawn args '/p:Configuration=Release;Platform=x64' ] Build started 2017/4/15 11:57:06. Project "E:\kibana\node_modules\node-sass\build\binding.sln" on node 1 (default targets). ValidateSolutionConfiguration: Building solution configuration "Release|x64". MSBUILD : error MSB3428: 未能加載 Visual C++ 組件“VCBuild.exe”。要解決此問題, 1) 安裝 .NET Fram ework 2.0 SDK;2) 安裝 Microsoft Visual Studio 2005;或 3) 如果將該組件安裝到了 其他位置,請將其位置添加到系統(tǒng) 路徑中。 [E:\kibana\node_modules\node-sass\build\binding.sln] Done Building Project "E:\kibana\node_modules\node-sass\build\binding.sln" (def ault targets) -- FAILED. Build FAILED. "E:\kibana\node_modules\node-sass\build\binding.sln" (default target) (1) -> (_src_\libsass target) -> MSBUILD : error MSB3428: 未能加載 Visual C++ 組件“VCBuild.exe”。要解決此問題 ,1) 安裝 .NET Fr amework 2.0 SDK;2) 安裝 Microsoft Visual Studio 2005;或 3) 如果將該組件安裝到 了其他位置,請將其位置添加到 系統(tǒng)路徑中。 [E:\kibana\node_modules\node-sass\build\binding.sln] 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.23 gyp ERR! build error gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ` failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (E:\kibana\node_modules\node-gyp\lib\b uild.js:285:23) gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at ChildProcess.emit (events.js:191:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_proces s.js:204:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "E:\\kibana\\node_modules \\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_ cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd E:\kibana\node_modules\node-sass gyp ERR! node -v v6.2.0 gyp ERR! node-gyp -v v3.6.0 gyp ERR! not ok Build failed npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\ba bel-cli\node_modules\chokidar\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@ 1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"} ) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\ch okidar\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@ 1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"} ) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\wa tchpack\node_modules\chokidar\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@ 1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"} ) npm WARN grunt-angular-translate@0.3.0 requires a peer of grunt@~0.4.0 but none was installed. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@3.8.0 postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@3.8.0 postinstall script 'node scripts/build.js '. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the node-sass package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node scripts/build.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs node-sass npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls node-sass npm ERR! There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\15061857\AppData\Roaming\npm-cache\_logs\2017-04-15T03_57_ 07_545Z-debug.log
看著這報錯信息,看到有文件下載出現(xiàn)404,然后我又去找文件,結(jié)果搞hosts文件,我以為是python問題,然后重裝各種版本python…
花了3小時,試了網(wǎng)上無數(shù)種答案,沒有可以解決的
解決方案一(有可能你還是不會成功,因為我也試了,這種方法以前是可以的)
將sass-loader和node-sass的版本號提高到最新版,目前的最新版如下(2019年7月12日)
“sass-loader”: “^7.1.0”,
“node-sass”: “^4.12.0”,
如圖所示,把package.json文件修改一下
然后再執(zhí)行如下命令安裝
npm i sass-loader npm i node-sass
2020-05-06更新
這個問題出現(xiàn)的原因往往是 Node-sass 的版本問題,可能的一個原因是:因為版本太老所以會導致有的依賴項已經(jīng)找不到了,公司有一個4年前的老項目就是這種問題,上面修改Node-sass的版本為4.12并不一定適合所有項目,可以多測試幾個版本,如果上面的版本失敗了可以試一試這個版本
"node-sass": "^4.13.1", "sass-loader": "^4.1.1",
2021-06-06更新
Nodejs版本切換為13.6,這樣才可以匹配上node sass的版本
簡單的方法是,先卸載nodejs,然后安裝13.6版本的
Nodejs13.6版本官網(wǎng)下載
仍然失敗怎么辦?那就試試第二種解決方案
發(fā)現(xiàn): gyp ERR! build error 應該是沒有安裝什么
解決辦法二:
主要是windows平臺缺少編譯環(huán)境,
1、先運行:
npm install -g node-gyp
2、然后運行:
npm install --global --production windows-build-tools 可以自動安裝跨平臺的編譯器:gym注:第二句執(zhí)行下載好msi文件卡著不動不安裝 , 手動去對應的目錄底下安裝一下 在執(zhí)行一遍。
本以為萬事大吉 一執(zhí)行 npm install node-sass --save-dev 悲劇的事情上演了
> node-sass@3.13.1 install E:\web_hwf\Vue\02app\node_modules\node-sass > node scripts/install.js Downloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node": HTTP error 404 Not Found Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 > node-sass@3.13.1 postinstall E:\web_hwf\Vue\02app\node_modules\node-sass > node scripts/build.js Building: E:\26_nodejs\node.exe E:\web_hwf\Vue\02app\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ 'E:\\26_nodejs\\node.exe', gyp verb cli 'E:\\web_hwf\\Vue\\02app\\node_modules\\node-gyp\\bin\\node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' ] gyp info using node-gyp@3.6.2 gyp info using node@10.1.0 | win32 | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "C:\Python27\python.exe" in the PATH gyp verb `which` succeeded C:\Python27\python.exe C:\Python27\python.exe gyp verb check python version `C:\Python27\python.exe -c "import platform; print(platform.python_version());"` returned: "2.7.14\r\n" gyp verb get node dir no --target version specified, falling back to host node version: 10.1.0 gyp verb command install [ '10.1.0' ] gyp verb install input version string "10.1.0" gyp verb install installing version: 10.1.0 gyp verb install --ensure was passed, so won't reinstall if already installed gyp verb install version is already installed, need to check "installVersion" gyp verb got "installVersion" 9 gyp verb needs "installVersion" 9 gyp verb install version is good gyp verb get node dir target node version installed: 10.1.0 gyp verb build dir attempting to create "build" dir: E:\web_hwf\Vue\02app\node_modules\node-sass\build gyp verb build dir "build" dir needed to be created? E:\web_hwf\Vue\02app\node_modules\node-sass\build gyp verb build/config.gypi creating config file gyp verb build/config.gypi writing out config file: E:\web_hwf\Vue\02app\node_modules\node-sass\build\config.gypi gyp verb config.gypi checking for gypi file: E:\web_hwf\Vue\02app\node_modules\node-sass\config.gypi gyp verb common.gypi checking for gypi file: E:\web_hwf\Vue\02app\node_modules\node-sass\common.gypi gyp verb gyp gyp format was not specified; forcing "msvs" gyp info spawn C:\Python27\python.exe gyp info spawn args [ 'E:\\web_hwf\\Vue\\02app\\node_modules\\node-gyp\\gyp\\gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'msvs', gyp info spawn args '-G', gyp info spawn args 'msvs_version=2015', gyp info spawn args '-I', gyp info spawn args 'E:\\web_hwf\\Vue\\02app\\node_modules\\node-sass\\build\\config.gypi', gyp info spawn args '-I', gyp info spawn args 'E:\\web_hwf\\Vue\\02app\\node_modules\\node-gyp\\addon.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\\Users\\Administrator\\.node-gyp\\10.1.0\\include\\node\\common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=C:\\Users\\Administrator\\.node-gyp\\10.1.0', gyp info spawn args '-Dnode_gyp_dir=E:\\web_hwf\\Vue\\02app\\node_modules\\node-gyp', gyp info spawn args '-Dnode_lib_file=C:\\Users\\Administrator\\.node-gyp\\10.1.0\\<(target_arch)\\node.lib', gyp info spawn args '-Dmodule_root_dir=E:\\web_hwf\\Vue\\02app\\node_modules\\node-sass', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'E:\\web_hwf\\Vue\\02app\\node_modules\\node-sass\\build', gyp info spawn args '-Goutput_dir=.' ] gyp verb command build [] gyp verb build type Release gyp verb architecture x64 gyp verb node dev dir C:\Users\Administrator\.node-gyp\10.1.0 gyp verb found first Solution file build/binding.sln gyp verb could not find "msbuild.exe" in PATH - finding location in registry gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe gyp info spawn args [ 'build/binding.sln', gyp info spawn args '/nologo', gyp info spawn args '/p:Configuration=Release;Platform=x64' ] Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch. Build started 2018/6/6 15:52:53. Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.sln" on node 1 (default targets). ValidateSolutionConfiguration: Building solution configuration "Release|x64". Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.sln" (1) is building "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.vcxproj.metaproj" (2) on node 1 (default targets). Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.vcxproj.metaproj" (2) is building "E:\web_hwf\Vue\02app\node_modules\node-sass\build\src\libsass.vcxproj" (3) on node 1 (default targets). E:\web_hwf\Vue\02app\node_modules\node-sass\build\src\libsass.vcxproj(20,3): error MSB4019: The imported project "E:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. Done Building Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\src\libsass.vcxproj" (default targets) -- FAILED. Done Building Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.vcxproj.metaproj" (default targets) -- FAILED. Done Building Project "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.sln" (default targets) -- FAILED. Build FAILED. "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.sln" (default target) (1) -> "E:\web_hwf\Vue\02app\node_modules\node-sass\build\binding.vcxproj.metaproj" (default target) (2) -> "E:\web_hwf\Vue\02app\node_modules\node-sass\build\src\libsass.vcxproj" (default target) (3) -> E:\web_hwf\Vue\02app\node_modules\node-sass\build\src\libsass.vcxproj(20,3): error MSB4019: The imported project "E:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.07 gyp ERR! build error gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (E:\web_hwf\Vue\02app\node_modules\node-gyp\lib\build.js:258:23) gyp ERR! stack at ChildProcess.emit (events.js:182:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "E:\\26_nodejs\\node.exe" "E:\\web_hwf\\Vue\\02app\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd E:\web_hwf\Vue\02app\node_modules\node-sass gyp ERR! node -v v10.1.0 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok Build failed with error code: 1 npm WARN rollback Rolling back source-map@0.4.4 failed (this is probably harmless): EPERM: operation not permitted, lstat 'E:\web_hwf\Vue\02app\node_modules\scss-tokenizer\node_modules' npm WARN eslint-config-standard@6.2.1 requires a peer of eslint-plugin-promise@>=3.3.0 but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@3.13.1 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2018-06-06T07_52_55_703Z-debug.log
解決辦法:
保存后 刪除之前安裝失敗的包(第一次安裝請?zhí)^此步)
npm uninstall node-sass
重新安裝
npm install node-sass
解決辦法三,重新配置node-sass
通常在各種方式都試過之后還是不行的時候,我們要考慮下是不是遺忘了哪個細節(jié)?
緩存!
沒錯,可能我們思路本來都是對的,但是實際在運行時并沒有按照我們預期的去執(zhí)行,緩存就是可能導致這種情況的因素之一。
現(xiàn)在前端安裝依賴大家常用的工具是npm和yarn
而這兩者都有各自的緩存機制,有時候,第一次安裝node-sass失敗后,可能這個包就已經(jīng)被緩存了,導致我們后續(xù)再進行安裝時,就
不再會從遠程服務器或者是代理去拉取了。這就導致了一個死循環(huán),永遠拉不到正確的文件。
成因
其實node-sass安裝不成功的跟本原因大家基本都清楚,就是他在安裝過程中,需要用到一個二進制文件:binding.node,但是坑爹的是,這個二進制文件在“外面”,也就是需要科學上網(wǎng)才能獲取,這就導致了絕大部分的安裝失敗。
除此之外,其實還有一些是因為通過設置各種代理之后,仍然不能獲取到正確的binding.node文件,具體原因可能多種多樣,但其實我們不需要關(guān)心這些問題,我們知道了問題的成因,那么直接從根源上解決問題即可。
解決辦法
分析清除了成因之后,解決問題就相對容易多了。既然node-sass總是從緩存拉取,那么我們就在緩存那里,直接把正確的文件放在那里,這樣在安裝node-sass時,直接從緩存中拉倒了正確的binding.node文件,問題便得以解決。
所以我們要做以下幾件事情:
1、檢測當前環(huán)境中,node-sass要使用的binding.node對應的版本
2、獲取到對應版本的binding.node
3、將獲取到的binding.node放到緩存中
操作步驟
1、查看當前環(huán)境適用的binding.node
node -p "[process.platform, process.arch, process.versions.modules].join('-')"
2、到這里下載對應版本的文件。鏈接地址: https://github.com/sass/node-sass/releases
3、將下載好的文件放入緩存目錄中
yarn緩存目錄:C:Users你的用戶名-AppData下的文件夾Local下的文件夾Yarn下的文件夾Cache
npm緩存目錄:C:Users你的用戶名-AppData下的文件夾Roaming下的文件夾npm-cache下的node-sass
注意
node-sass最終安裝正確的情況下,目錄結(jié)構(gòu)是這樣的:
node-sass| -... -vender| -win32-x64-93 -binding.node
所以為了保證正確安裝,我們需要按照這個格式把下載到的文件放到緩存的目錄下。
這里,win32-x64-93在不同的環(huán)境下可能有不同的版本,要注意看一下你本地對應的是什么版本。
查看版本上面給出了一個命令
(node -p "[process.platform, process.arch, process.versions.modules].join('-')"),可以試一下。
查看版本還有一種方式,就是當你第一次安裝失敗時,你去node-modules中去找node-sass目錄,然后找到vender目錄,進去就能看到你的環(huán)境下,building.node對應的版本了。
我本地的目錄結(jié)構(gòu)如下,供參考:
4、重新安裝node-sass
總結(jié)
到此這篇關(guān)于node-sass安裝失敗解決方法的文章就介紹到這了,更多相關(guān)node-sass安裝失敗解決內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
pnpm workspace管理monorepo項目使用過程詳解
這篇文章主要為大家介紹了pnpm workspace管理monorepo項目使用過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10從零開始學習Node.js系列教程之基于connect和express框架的多頁面實現(xiàn)數(shù)學運算示例
這篇文章主要介紹了Node.js基于connect和express框架的多頁面實現(xiàn)數(shù)學運算,簡單講述了connect和express框架的原理及數(shù)學運算相關(guān)操作技巧,需要的朋友可以參考下2017-04-04node.js基于dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務器和客戶端操作示例
這篇文章主要介紹了node.js基于dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務器和客戶端操作,結(jié)合實例形式分析了node.js使用dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務器和客戶端,以及進行UDP廣播、組播相關(guān)操作技巧,需要的朋友可以參考下2020-02-02