vue项目用npm安装sass包遇到的问题及解决办法
idea启动vue程序,浏览器访问时出现如下情况的关于node-sass的错误:
错误1:
module build failed (from ./node_modules/sass-loader/dist/cjs.js)
error:cannot find module 'node-sass'
错误2:
module build failed (from ./node_modules/sass-loader/dist/cjs.js)
error:no such file or directory, open 'd:\sourceproject\sichebangong\car-pub-vue\node_modules\node-sass\lib\index.js'
failed to compile. ./src/back/views/user/login.vue?vue&type=style&index=0&id=1503f165&lang=scss&scoped=true& (./node_modules/css-loader??ref--8-oneof-1-1!./node_modules/@vue/cli-service/node_modules/vue-loader/lib/loaders/stylepostloader.js!./node_modules/postcss-loader/src??ref--8-oneof-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneof-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/back/views/user/login.vue?vue&type=style&index=0&id=1503f165&lang=scss&scoped=true&) module build failed (from ./node_modules/sass-loader/dist/cjs.js): error: enoent: no such file or directory, open 'd:\sourceproject\sichebangong\car-pub-vue\node_modules\node-sass\lib\index.js' at object.opensync (fs.js:440:3) at object.readfilesync (fs.js:342:35) at object.module._extensions..js (internal/modules/cjs/loader.js:994:22) at module.load (internal/modules/cjs/loader.js:815:32) at function.module._load (internal/modules/cjs/loader.js:727:14) at module.require (internal/modules/cjs/loader.js:852:19) at require (internal/modules/cjs/helpers.js:74:18) at getdefaultsassimpl (d:\sourceproject\sichebangong\car-pub-vue\node_modules\sass-loader\dist\index.js:198:10) at object.loader (d:\sourceproject\sichebangong\car-pub-vue\node_modules\sass-loader\dist\index.js:80:29)
查看项目的node_modules目录,有sass-loader,却没有node-sass。
安装sass吧。命令:npm install node-sass -g
提示了好多错误,如
cannot download "https://github.com/sass/node-sass/releases/download/v4.13.0/win32-x64-72_binding.node", 原因是sockettimedout。
msbuild : error msb4132: 无法识别工具版本“2.0”。可用的工具版本为 "4.0"
npm warn notsup skipping optional dependency: unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
python
网上资料有很多,不过每个人的情况不一样,所以,并没有解决我的问题。
最终解决办法是使用cnpm命令
cnpm uninstall node-sass cnpm install node-sass
成功安装sass包。