迪克猪的博客
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Failed to resolve loader sass loader

问题描述:

$ yarn run build:mp-weixin
Debugger attached.
yarn run v1.22.11
$ cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build
Debugger attached.
Debugger attached.
小程序各家浏览器内核及自定义组件实现机制存在差异,可能存在样式布局兼容问题,参考:https://uniapp.dcloud.io/matter?id=mp

⠧  开始编译当前项目至 mp-weixin 平台...

 ERROR  Failed to compile with 1 error                                                                                                                             11:57:50 PM

Failed to resolve loader: sass-loader
You may need to install it.
 ERROR  Build failed with errors.
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Waiting for the debugger to disconnect...

安装cnpm:

$ npm install cnpm -g
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/cnpm -> /usr/local/lib/node_modules/cnpm/bin/cnpm
+ cnpm@7.0.0
updated 173 packages in 156.974s

首先安装sass-loader:

$ cnpm install sass-loader -D
✔ Installed 1 packages
✔ Linked 3 latest versions
✔ Run 0 scripts
peerDependencies WARNING sass-loader@latest requires a peer of fibers@>= 3.1.0 but none was installed
peerDependencies WARNING sass-loader@latest requires a peer of node-sass@^4.0.0 || ^5.0.0 || ^6.0.0 but none was installed
peerDependencies WARNING sass-loader@latest requires a peer of sass@^1.3.0 but none was installed
peerDependencies WARNING sass-loader@latest requires a peer of webpack@^5.0.0 but webpack@4.46.0 was installed
✔ All packages installed (3 packages installed from npm registry, used 506ms(network 500ms), speed 146.7KB/s, json 3(16.23KB), tarball 57.12KB)

接下来会报错:Error:Cannot find module ‘node-sass’; 继续安装node-sass:

$ cnpm install node-sass -D
✔ Installed 1 packages
✔ Linked 182 latest versions
[1/1] scripts.install node-sass@latest run "node scripts/install.js", root: "/Volumes/E/JYW/孔店村平台/programs/vue-mall-beautiful/node_modules/_node-sass@6.0.1@node-sass"
Downloading binary from https://cdn.npm.taobao.org/dist/node-sass/v6.0.1/darwin-x64-83_binding.node
Download complete
Binary saved to /Volumes/E/JYW/孔店村平台/programs/vue-mall-beautiful/node_modules/_node-sass@6.0.1@node-sass/vendor/darwin-x64-83/binding.node
Caching binary to /Users/zhushuyan/.npminstall_tarball/node-sass/6.0.1/darwin-x64-83_binding.node
[1/1] scripts.install node-sass@latest finished in 2s
[1/1] scripts.postinstall node-sass@latest run "node scripts/build.js", root: "/Volumes/E/JYW/孔店村平台/programs/vue-mall-beautiful/node_modules/_node-sass@6.0.1@node-sass"
Binary found at /Volumes/E/JYW/孔店村平台/programs/vue-mall-beautiful/node_modules/_node-sass@6.0.1@node-sass/vendor/darwin-x64-83/binding.node
Testing binary
Binary is fine
[1/1] scripts.postinstall node-sass@latest finished in 221ms
✔ Run 1 scripts
deprecate node-sass@6.0.1 › request@^2.88.0 request has been deprecated, see https://github.com/request/request/issues/3142
deprecate node-sass@6.0.1 › request@2.88.2 › har-validator@~5.1.3 this library is no longer supported
Recently updated (since 2021-08-03): 4 packages (detail see file /Volumes/E/JYW/孔店村平台/programs/vue-mall-beautiful/node_modules/.recently_updates.txt)
✔ All packages installed (205 packages installed from npm registry, used 6s(network 4s), speed 795.94KB/s, json 182(375.83KB), tarball 3.02MB)