npm run serve 编译项目,报如下错误:

 INFO  Starting development server...
98% after emitting CopyPlugin

ERROR Failed to compile with 18 errors

error in ./src/layout/components/TagsView/index.vue?vue&type=style&index=1&lang=scss&

Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.sassLoader


解决办法:

试了很多办法,都不行,cnpm等等,都还是报错,这个时候nodejs版本是10.16.3,实在没办法了,切换nodejs版本为12.11.0,这个是最新版本,按下面步骤执行命令,成功

一、直接npm install node-sass命令安装node-sass模块:如下安装成功

C:\Users\UserName>npm install node-sass

> node-sass@4.12.0 install D:\WS\gitee\uexam-mysql\source\vue\exam-admin\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.12.0/win32-x64-72_binding.node
Download complete ] - :
Binary saved to D:\WS\gitee\uexam-mysql\source\vue\exam-admin\node_modules\node-sass\vendor\win32-x64-72\binding.node
Caching binary to C:\Users\m16\AppData\Roaming\npm-cache\node-sass\4.12.0\win32-x64-72_binding.node

> node-sass@4.12.0 postinstall D:\WS\gitee\uexam-mysql\source\vue\exam-admin\node_modules\node-sass
> node scripts/build.js

Binary found at D:\WS\gitee\uexam-mysql\source\vue\exam-admin\node_modules\node-sass\vendor\win32-x64-72\binding.node
Testing binary
Binary is fine
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ node-sass@4.12.0
added 86 packages from 59 contributors and audited 26687 packages in 100.172s
found 416 vulnerabilities (413 high, 3 critical)
run `npm audit fix` to fix them, or `npm audit` for details

二、直接npm run serve编译项目,并会自动启动浏览器



注:如果已经安装的node-sass模块,但是不生效,可能是node-sass模块损坏,这个时候使用npm rebuild node-sass命令,重新编译下node-sass模块;