晚上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 ,說明可能該檔案破碎或者無法識別,以後還是要相信科學,相信報錯,少走彎路。