使用HbuilderX导入vue-cli创建的项目,使用HbuilderX内置的Terminal插件执行npm install之后,点击“运行”-“微信小程序”报错如下:
11:27:54.467 error during build: 11:27:54.469 Error: 11:27:54.469 You installed esbuild for another platform than the one you're currently using. 11:27:54.471 This won't work because esbuild is written with native code and needs to 11:27:54.472 install a platform-specific binary executable. 11:27:54.474 Specifically the "@esbuild/darwin-arm64" package is present but this platform 11:27:54.475 needs the "@esbuild/darwin-x64" package instead. People often get into this 11:27:54.477 situation by installing esbuild with npm running inside of Rosetta 2 and then 11:27:54.479 trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta 11:27:54.481 2 is Apple's on-the-fly x86_64-to-arm64 translation service). 11:27:54.482 If you are installing with npm, you can try ensuring that both npm and node are 11:27:54.484 not running under Rosetta 2 and then reinstalling esbuild. This likely involves 11:27:54.485 changing how you installed npm and/or node. For example, installing node with 11:27:54.486 the universal installer here should work: nodejs.org/en/download…. Or 11:27:54.487 you could consider using yarn instead of npm which has built-in support for 11:27:54.489 installing a package on multiple platforms simultaneously. 11:27:54.490 If you are installing with yarn, you can try listing both "arm64" and "x64" 11:27:54.491 in your ".yarnrc.yml" file using the "supportedArchitectures" feature: 11:27:54.492 yarnpkg.com/configurati… 11:27:54.498 Keep in mind that this means multiple copies of esbuild will be present. 11:27:54.500 Another alternative is to use the "esbuild-wasm" package instead, which works 11:27:54.502 the same way on all platforms. But it comes with a heavy performance cost and 11:27:54.502 can sometimes be 10x slower than the "esbuild" package, so you may also not 11:27:54.504 want to do that.
搜索互联网信息之后,定位到是新款Mac M系芯片和Intel架构不同,@esbuild差异导致。
如果你确实需要在 ARM64 架构上使用 esbuild,请确保你没有通过 Rosetta 2 运行终端或任何相关工具。你可以通过以下命令检查当前是否在 Rosetta 2 下运行:
bash
深色版本
sysctl sysctl.proc_translated
如果输出为 sysctl.proc_translated: 1,则表示你正在通过 Rosetta 2 运行。你可以通过关闭终端并重新启动一个新的非 Rosetta 2 终端来解决这个问题。
最终解决办法是点击“运行”-“终端”选择外部终端执行npm install,后续再点击“运行”-“微信小程序”,成功运行到微信开发者工具。
以上做填坑记录,留作备忘,也希望能帮助到网友。