m1 pro编译 vite/vue3 cli项目时编译报错

错误详情:

15:14:13.762 项目 'fcbmallwx' 开始编译...
15:14:14.766 编译器版本:3.5.3(vue3)
15:14:14.769 请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。
15:14:14.770 正在编译中...
15:14:14.774 failed to load config from /Users/xxx/uni-preset-vue/vite.config.js
15:14:14.777 error during build:
15:14:14.779 Error: 
15:14:14.780 You installed esbuild on another platform than the one you're currently using.
15:14:14.782 This won't work because esbuild is written with native code and needs to
15:14:14.783 install a platform-specific binary executable.
15:14:14.791 Specifically the "esbuild-darwin-arm64" package is present but this platform
15:14:14.791 needs the "esbuild-darwin-64" package instead. People often get into this
15:14:14.794 situation by installing esbuild on Windows or macOS and copying "node_modules"
15:14:14.796 into a Docker image that runs Linux, or by copying "node_modules" between
15:14:14.797 Windows and WSL environments.
15:14:14.799 If you are installing with npm, you can try not copying the "node_modules"
15:14:14.801 directory when you copy the files over, and running "npm ci" or "npm install"
15:14:14.803 on the destination platform after the copy. Or you could consider using yarn
15:14:14.803 instead which has built-in support for installing a package on multiple
15:14:14.805 platforms simultaneously.
15:14:14.807 If you are installing with yarn, you can try listing both this platform and the
15:14:14.814 other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
15:14:14.814 feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
15:14:14.818 Keep in mind that this means multiple copies of esbuild will be present.
15:14:14.820 Another alternative is to use the "esbuild-wasm" package instead, which works
15:14:14.822 the same way on all platforms. But it comes with a heavy performance cost and
15:14:14.823 can sometimes be 10x slower than the "esbuild" package, so you may also not
15:14:14.825 want to do that.

解决方法:

  1. pnpm 安装的话到这个文件 node_modules/.pnpm/esbuild@0.14.51/node_modules/esbuild-darwin-arm64 复制 esbuild-darwin-arm64 文件夹在同级目录下改名为 esbuild-darwin-64 即可
    在这里插入图片描述

  2. npm 或 yarn安装的话到 node_modules 目录复制 esbuild-darwin-arm64 文件夹改名为 esbuild-darwin-64 即可
    在这里插入图片描述
    esbuild-darwin-64 和 esbuild-darwin-arm64 两个文件夹都需要

问题原因:
推测是 vite 用 esbuild 编译时 hbuilderX 里面默认去找 esbuild-darwin-64 文件夹, 但是 m1 是 arm 架构下载到包是 esbuild-darwin-arm64 导致找不到对应的编译包就报错了

Logo

前往低代码交流专区

更多推荐