uni-app cli项目MAC m1 启动项目报错,命令启动没有问题

发布于 1周前 作者 sinazl 来自 Uni-App

uni-app cli项目MAC m1 启动项目报错,命令启动没有问题

产品分类:

uniapp/小程序/微信

PC开发环境操作系统:

Mac

PC开发环境操作系统版本号:

4.08

HBuilderX类型:

正式

HBuilderX版本号:

4.08

第三方开发者工具版本号:

1.06.2402040

基础库版本号:

3.3.3

项目创建方式:

HBuilderX

示例代码:

:09.646 请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布
12:07:09.659 正在编译中…
12:07:09.834 failed to load config from /Users/dalong/Documents/HBuilderProjects/uniapp-vue3/vite.config.js
12:07:09.850 error during build:
12:07:09.852 Error:
12:07:09.863 You installed esbuild for another platform than the one you’re currently using.
12:07:09.880 This won’t work because esbuild is written with native code and needs to
12:07:09.894 install a platform-specific binary executable.
12:07:09.909 Specifically the “@esbuild/darwin-arm64” package is present but this platform
12:07:09.911 needs the “@esbuild/darwin-x64” package instead. People often get into this
12:07:09.940 situation by installing esbuild with npm running inside of Rosetta 2 and then
12:07:09.956 trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
12:07:09.969 2 is Apple’s on-the-fly x86_64-to-arm64 translation service).
12:07:09.971 If you are installing with npm, you can try ensuring that both npm and node are
12:07:09.984 not running under Rosetta 2 and then reinstalling esbuild. This likely involves
12:07:09.987 changing how you installed npm and/or node. For example, installing node with
12:07:10.001 the universal installer here should work: https://nodejs.org/en/download/. Or
12:07:10.003 you could consider using yarn instead of npm which has built-in support for
12:07:10.017 installing a package on multiple platforms simultaneously.
12:07:10.019 If you are installing with yarn, you can try listing both “arm64” and “x64”
12:07:10.033 in your “.yarnrc.yml” file using the “supportedArchitectures” feature:
12:07:10.036 https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
12:07:10.051 Keep in mind that this means multiple copies of esbuild will be present.
12:07:10.053 Another alternative is to use the “esbuild-wasm” package instead, which works
12:07:10.068 the same way on all platforms. But it comes with a heavy performance cost and
12:07:10.070 can sometimes be 10x slower than the “esbuild” package, so you may also not
12:07:10.086 want to do that.
12:07:10.102 at generateBinPath (/Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1841:17)
12:07:10.117 at esbuildCommandAndArgs (/Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1922:33)
12:07:10.133 at ensureServiceIsRunning (/Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/esbuild@0.16.17/node_modules/esbuild/lib/main.js:2087:25)
12:07:10.149 at build (/Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1978:26)
12:07:10.166 at bundleConfigFile (file:///Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61966:26)
12:07:10.183 at loadConfigFromFile (file:///Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61942:31)
12:07:10.185 at resolveConfig (file:///Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/dist/node/chunks/dep-0bae2027.js:61564:34)
12:07:10.203 at doBuild (file:///Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/dist/node/chunks/dep-0bae2027.js:44332:26)
12:07:10.221 at Module.build (file:///Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/dist/node/chunks/dep-0bae2027.js:44321:22)
12:07:10.239 at /Users/dalong/Documents/HBuilderProjects/uniapp-vue3/node_modules/.store/vite@4.0.3/node_modules/vite/index.cjs:23:55

cli项目,运行报这个错,m1芯片,用命令启动没有问题

操作步骤:

  • 使用工具里面的运行-运行到小程序模拟器-微信开发者工具

预期结果:

  • 正常启动小程序

实际结果:

  • 报错

7 回复

从别人那儿偷来的, node_modules/@esbuild/darwin-arm64, 复制一份darwin-arm64文件夹并改名darwin-x64,


我也遇到了

没人关注吗

没人关注?我也遇到了

试试使用 pnpm install --force 强制重新安装所有依赖项。我是m3pro芯片出现了这个问题,现在好了。

感谢老哥,大大地管用

在 MAC M1 上使用 uni-app CLI 项目时,可能会遇到一些兼容性问题,导致项目启动时报错。以下是一些常见的解决方案和排查步骤,帮助你解决这个问题:

1. 确保环境配置正确

首先,确保你的开发环境配置正确。以下是 uni-app 开发所需的基本环境:

  • Node.js: 确保安装了 Node.js,并且版本符合 uni-app 的要求。
  • npm/yarn: 确保安装了 npm 或 yarn,并且版本是最新的。
  • HBuilderX: 如果你使用的是 HBuilderX,确保它是最新版本。

你可以通过以下命令检查 Node.js 和 npm 的版本:

node -v
npm -v

2. 使用 Rosetta 2 运行终端

由于 MAC M1 使用的是 ARM 架构,某些依赖可能还没有完全兼容。你可以尝试在 Rosetta 2 模式下运行终端,以确保所有依赖都能正常工作。

  1. 找到你的终端应用(如 Terminal 或 iTerm2)。
  2. 右键点击应用图标,选择“获取信息”。
  3. 在“通用”选项卡中,勾选“使用 Rosetta 打开”。
  4. 重新启动终端,并尝试再次运行项目。

3. 清理并重新安装依赖

有时候,依赖包的缓存或安装问题可能导致项目启动失败。你可以尝试清理并重新安装依赖:

# 删除 node_modules 和 package-lock.json
rm -rf node_modules package-lock.json

# 重新安装依赖
npm install

4. 检查项目配置文件

确保项目的配置文件(如 package.jsonvue.config.js 等)没有错误。特别是 vue.config.js 文件中的配置项,确保它们与 uni-app 的要求一致。

5. 检查错误日志

如果项目启动时报错,仔细查看错误日志,找出具体的错误信息。错误日志通常会给出详细的提示,帮助你定位问题。

6. 更新 CLI 工具

确保你使用的 uni-app CLI 工具是最新版本。你可以通过以下命令更新:

npm install -g [@vue](/user/vue)/cli [@dcloudio](/user/dcloudio)/uni-cli
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!