1.第一次碰到这种问题很懵,因为电脑上装有node也配置有sass,不懂为什么会出现这种错,错误如下

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
02:01:43.383 ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
02:01:43.390 Error: Missing binding /Users/qinky/WebstormProjects/qingchi_uni/node_modules/node-sass/vendor/darwin-x64-57/binding.node
02:01:43.390 Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 8.x
02:01:43.395 Found bindings for the following environments:
02:01:43.396 - OS X 64-bit with Node.js 10.x
02:01:43.401 This usually happens because your environment has changed since running npm install.
02:01:43.401 Run npm rebuild node-sass to download the binding for your current environment.
02:01:43.408 at module.exports (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/node-sass/lib/binding.js:15:13)
02:01:43.409 at Object. (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/node-sass/lib/index.js:14:35)
02:01:43.416 at Module._compile (module.js:652:30)
02:01:43.423 at Object.Module._extensions…js (module.js:663:10)
02:01:43.429 at Module.load (module.js:565:32)
02:01:43.429 at tryModuleLoad (module.js:505:12)
02:01:43.435 at Function.Module._load (module.js:497:3)
02:01:43.435 at Module.require (module.js:596:17)
02:01:43.460 at require (internal/module.js:11:18)
02:01:43.461 at getDefaultSassImplementation (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/sass-loader/dist/getDefaultSassImplementation.js:24:10)
02:01:43.468 at getSassImplementation (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/sass-loader/dist/getSassImplementation.js:19:72)
02:01:43.476 at Object.loader (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/sass-loader/dist/index.js:40:61)
02:01:43.482 at runLoaders (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/webpack/lib/NormalModule.js:301:20)
02:01:43.482 at /Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:367:11
02:01:43.509 at /Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:233:18
02:01:43.510 at runSyncOrAsync (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
02:01:43.519 at iterateNormalLoaders (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
02:01:43.521 at iterateNormalLoaders (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
02:01:43.528 at /Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:236:3
02:01:43.529 at Object.context.callback (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
02:01:43.560 at Object.module.exports (/Users/qinky/WebstormProjects/qingchi_uni/node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js:60:10)
02:01:43.560 ERROR Build failed with errors.

2.如果你的错误是一样的可以参考,错误原因是电脑配置的node版本是12,而HBuild有个内置的node,是v8.10.0。在打包发布的时候会使用HBuild内置的node,所以是会报错的。

3.总结来说,我们node_module下的包是用高版本的node生成的,但是在打包的时候使用的HBuild里面的低版本的node,所以就会报错。
4.解决方法:
cd /Applications/HBuilderX.app/Contents/HBuilderX/plugins/node

mv node node-v8

ln -s /usr/local/bin/node /Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node

5.可以参考详细解释
https://blog.tcs-y.com/2020/05/18/uniapp-node-sass-error/

https://ask.dcloud.net.cn/question/82024

GitHub 加速计划 / no / node-sass
8.5 K
1.33 K
下载
:rainbow: Node.js bindings to libsass
最近提交(Master分支:2 个月前 )
6081731a Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 9 个月前
62c0f46c Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 9 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐