晚上10点左右,刚好说想研究一下uniapp项目中怎么进行自动测试,于是跟着插件的官方教程开始配置测试环境,写好了一个简单的测试脚本,然后图形化操作IDE运行测试,却报错了一大片错误信息,如下所示:
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): 02:12:29.703 [sunnywasher-uniapp:mp-weixin] ModuleBuildError: Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 02:12:29.721 [sunnywasher-uniapp:mp-weixin] Error: dlopen(/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/vendor/darwin-x64-93/binding.node, 0x0001): tried: '/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/vendor/darwin-x64-93/binding.node' (not a mach-o file), '/usr/local/lib/binding.node' (no such file), '/usr/lib/binding.node' (no such file) 02:12:29.740 [sunnywasher-uniapp:mp-weixin] at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18) 02:12:29.762 [sunnywasher-uniapp:mp-weixin] at Module.load (node:internal/modules/cjs/loader:981:32) 02:12:29.763 [sunnywasher-uniapp:mp-weixin] at Function.Module._load (node:internal/modules/cjs/loader:822:12) 02:12:29.783 [sunnywasher-uniapp:mp-weixin] at Module.require (node:internal/modules/cjs/loader:1005:19) 02:12:29.784 [sunnywasher-uniapp:mp-weixin] at require (node:internal/modules/cjs/helpers:102:18) 02:12:29.803 [sunnywasher-uniapp:mp-weixin] at /Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/lib/binding.js:19:10 02:12:29.804 [sunnywasher-uniapp:mp-weixin] at Object.<anonymous> (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/lib/index.js:14:35) 02:12:29.823 [sunnywasher-uniapp:mp-weixin] at Module._compile (node:internal/modules/cjs/loader:1101:14) 02:12:29.824 [sunnywasher-uniapp:mp-weixin] at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) 02:12:29.846 [sunnywasher-uniapp:mp-weixin] at Module.load (node:internal/modules/cjs/loader:981:32) 02:12:29.847 [sunnywasher-uniapp:mp-weixin] at Function.Module._load (node:internal/modules/cjs/loader:822:12) 02:12:29.870 [sunnywasher-uniapp:mp-weixin] at Module.require (node:internal/modules/cjs/loader:1005:19) 02:12:29.871 [sunnywasher-uniapp:mp-weixin] at require (node:internal/modules/cjs/helpers:102:18) 02:12:29.892 [sunnywasher-uniapp:mp-weixin] at Object.<anonymous> (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/index.js:8:22) 02:12:29.894 [sunnywasher-uniapp:mp-weixin] at Module._compile (node:internal/modules/cjs/loader:1101:14) 02:12:29.917 [sunnywasher-uniapp:mp-weixin] at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) 02:12:29.918 [sunnywasher-uniapp:mp-weixin] at /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/NormalModule.js:316:20 02:12:29.940 [sunnywasher-uniapp:mp-weixin] at /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:367:11 02:12:29.943 [sunnywasher-uniapp:mp-weixin] at /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:233:18 02:12:29.968 [sunnywasher-uniapp:mp-weixin] at runSyncOrAsync (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:143:3) 02:12:29.970 [sunnywasher-uniapp:mp-weixin] at iterateNormalLoaders (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:232:2) 02:12:29.993 [sunnywasher-uniapp:mp-weixin] at iterateNormalLoaders (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:221:10) 02:12:29.995 [sunnywasher-uniapp:mp-weixin] at /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:236:3 02:12:30.017 [sunnywasher-uniapp:mp-weixin] at Object.context.callback (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/loader-runner/lib/LoaderRunner.js:111:13) 02:12:30.019 [sunnywasher-uniapp:mp-weixin] at Object.<anonymous> (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js:60:8)
这个报错非常诡异,我最开始怀疑是node版本问题。我用nvm不断切换不同版本,甚至把HbuilderX的插件里面的node删除,用nvm使用的node创造软连接给它。然而并不解决问题,我google+sogou连续查阅相关问题,但是大部分都在说rebuild一下sass之类的。二node-sass本身安装也是正常的,我陷入了思维的死循环。最后熬夜到了2点,终于发现了:原来是通过淘宝cdn资源下载的binding.node文件有问题,去github上下载就是正确的了。github地址为:https://github.com/sass/node-sass/releases
以我本人为例,我下载了这个版本的文件https://github.com/sass/node-sass/releases/download/v7.0.1/darwin-x64-93_binding.node到/Applications/HBuilderX.app/Contents/HBuilderX/plugins/compile-node-sass/node_modules/node-sass-china/vendor/darwin-x64-93文件夹下
并把darwin-x64-93_binding.node文件重命名为binding.node
来来回回折腾,还是报错信息是最准确了,说的是binding.node is not a mach-o file ,说明可能该文件破碎或者无法识别,以后还是要相信科学,相信报错,少走弯路。