uniapp vue3+vite脚手架版本M1构建问题

2,148 阅读2分钟

报错信息如下

failed to load config from /Users/listenhua/project/myself/tsk/uniapp/vite.config.js
error during build:
Error: 
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "@esbuild/darwin-arm64" package is present but this platform
needs the "@esbuild/darwin-x64" package instead. People often get into this
situation by installing esbuild with npm running inside of Rosetta 2 and then
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
If you are installing with npm, you can try ensuring that both npm and node are
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
changing how you installed npm and/or node. For example, installing node with
the universal installer here should work: https://nodejs.org/en/download/. Or
you could consider using yarn instead of npm which has built-in support for
installing a package on multiple platforms simultaneously.
If you are installing with yarn, you can try listing both "arm64" and "x64"
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.
Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.
    at generateBinPath (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:1841:17)
    at esbuildCommandAndArgs (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:1922:33)
    at ensureServiceIsRunning (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:2087:25)
    at build (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:1978:26)
    at bundleConfigFile (file:///Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61966:26)
    at loadConfigFromFile (file:///Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61942:31)
    at resolveConfig (file:///Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61564:34)
    at doBuild (file:///Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/dist/node/chunks/dep-0bae2027.js:44332:26)
    at Module.build (file:///Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/dist/node/chunks/dep-0bae2027.js:44321:22)
    at /Users/listenhua/project/myself/tsk/uniapp/node_modules/vite/index.cjs:23:55

我去查阅了论坛许多相关信息,安装了相关依赖包

yarn add esbuild-darwin-arm64

后面还是报了如下的错误

✘ [ERROR] Cannot start service: Host version "0.16.17" does not match binary version "0.15.18"
1 error
failed to load config from /Users/listenhua/project/myself/tsk/uniapp/vite.config.js
error during build:
Error: The service was stopped
    at /Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:1145:25
    at Object.responseCallbacks.<computed> (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:701:9)
    at Socket.afterClose (/Users/listenhua/project/myself/tsk/uniapp/node_modules/esbuild/lib/main.js:691:28)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

后面又查阅了许多文章,还是没能解决,但是根据报错,我又发现esbuild-darwin-arm64依赖包的版本最新为0.15.18,但是官方编译却要求0.16.17,所以我打算自己去尝试一下,于是打开了提示中文件路径/node_modules/esbuild/lib/main.js全局替换了0.16.170.15.18

然后就运行成功了

本文也只是提供解决方法之一,也希望uniapp早日解决这个问题吧

不知道这样子处理是否有什么问题,如发现问题或者有其他更好的解决方案也欢迎大家分享一下