buguge - Keep it simple,stupid

知识就是力量,但更重要的,是运用知识的能力why buguge?

导航

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命令取代npm,成功安装sass包。

cnpm uninstall node-sass
cnpm install node-sass

 

posted on 2019-12-25 18:33  buguge  阅读(12652)  评论(1编辑  收藏  举报