在部署vue-admin-template-master时,使用
npm run dev
报错:
module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
Require stack:
- C:\Users\s2020\Downloads\Compressed\code\Back\odule build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
Require stack:
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\sass-loader\lib\loader.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\loader-runner\lib\loadLoader.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\loader-runner\lib\LoaderRunner.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\NormalModule.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\NormalModuleFactory.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\Compiler.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\webpack.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack-dev-server\lib\Server.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.sassLoader (C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\sass-loader\lib\loader.js:24:22)
@ ./node_modules/vue-style-loader!./node_modules/css-loader??ref--10-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/lib??ref--10-2!./node_modules/sass-loader/lib/loader.js??ref--10-3!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Breadcrumb/index.vue?vue&type=style&index=0&id=b50ef614&rel=stylesheet%2Fscss&lang=scss&scoped=true& 4:14-421 14:3-18:5 15:22-429
@ ./src/components/Breadcrumb/index.vue?vue&type=style&index=0&id=b50ef614&rel=stylesheet%2Fscss&lang=scss&scoped=true&
@ ./src/components/Breadcrumb/index.vue
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/views/layout/components/Navbar.vue?vue&type=script&lang=js&
@ ./src/views/layout/components/Navbar.vue?vue&type=script&lang=js&
@ ./src/views/layout/components/Navbar.vue
@ ./src/views/layout/components/index.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/views/layout/Layout.vue?vue&type=script&lang=js&
@ ./src/views/layout/Layout.vue?vue&type=script&lang=js&
@ ./src/views/layout/Layout.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:9528 (webpack)/hot/dev-server.js ./src/main.js\node_modules\sass-loader\lib\loader.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\loader-runner\lib\loadLoader.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\loader-runner\lib\LoaderRunner.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\NormalModule.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\NormalModuleFactory.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\Compiler.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack\lib\webpack.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack-dev-server\lib\Server.js
- C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.sassLoader (C:\Users\s2020\Downloads\Compressed\code\Back\vue-admin-template-master\node_modules\sass-loader\lib\loader.js:24:22)
@ ./node_modules/vue-style-loader!./node_modules/css-loader??ref--10-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/lib??ref--10-2!./node_modules/sass-loader/lib/loader.js??ref--10-3!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Breadcrumb/index.vue?vue&type=style&index=0&id=b50ef614&rel=stylesheet%2Fscss&lang=scss&scoped=true& 4:14-421 14:3-18:5 15:22-429
@ ./src/components/Breadcrumb/index.vue?vue&type=style&index=0&id=b50ef614&rel=stylesheet%2Fscss&lang=scss&scoped=true&
@ ./src/components/Breadcrumb/index.vue
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/views/layout/components/Navbar.vue?vue&type=script&lang=js&
@ ./src/views/layout/components/Navbar.vue?vue&type=script&lang=js&
@ ./src/views/layout/components/Navbar.vue
@ ./src/views/layout/components/index.js
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/views/layout/Layout.vue?vue&type=script&lang=js&
@ ./src/views/layout/Layout.vue?vue&type=script&lang=js&
@ ./src/views/layout/Layout.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:9528 (webpack)/hot/dev-server.js ./src/main.js
于是使用
npm install node-sass --save-dev
使用但是还是报错,忘记自己的镜像源改成国内的,使用淘宝
npm install -g cnpm --registry=https://registry.npm.taobao.org
再使用cnpm install node-sass --save-dev
npm run dev
OK
第二种情况可能是npm 与 node 版本不对应造成的错误
使用
node -v 和 npm -v
查看版本信息,到下面这个网站去查看对应的信息
删除node_mouldes 重新使用
npm install
npm run dev
看看能否跑起来。
踩坑不易,如果对你有用,收藏点赞谢谢。