uni-app Mac系统下cli项目无法编译启动
uni-app Mac系统下cli项目无法编译启动
| 信息类别 | 详情 |
|---|---|
| 产品分类 | uniapp/H5 |
| PC开发环境 | Mac |
| 操作系统版本 | MacOS 14.4.1 M系列芯片 |
| HBuilderX类型 | 正式 |
| HBuilderX版本 | 4.15 |
| 浏览器平台 | Chrome |
| 浏览器版本 | 124.0.6367.207 |
| 项目创建方式 | HBuilderX |
操作步骤:
npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
预期结果:
正常编译
实际结果:
15:15:56.948 项目 my-vue3-project 开始编译
15:15:57.813 请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。
15:15:57.813 vite是按需编译,运行时点击某个未编译页面会先编译后加载,导致显示较慢,发行后无此问题。
15:15:57.817 编译器版本:4.07(vue3)
15:15:57.817 正在编译中...
15:15:57.902 failed to load config from /Users/xxx/Desktop/dmeo/my-vue3-project/vite.config.ts
15:15:57.920 error when starting dev server:
15:15:57.920 Error:
15:15:57.920 You installed esbuild for another platform than the one you're currently using.
15:15:57.920 This won't work because esbuild is written with native code and needs to
15:15:57.920 install a platform-specific binary executable.
15:15:57.920 Specifically the "@esbuild/darwin-arm64" package is present but this platform
15:15:57.920 needs the "@esbuild/darwin-x64" package instead. People often get into this
15:15:57.920 situation by installing esbuild with npm running inside of Rosetta 2 and then
15:15:57.920 trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
15:15:57.920 2 is Apple's on-the-fly x86_64-to-arm64 translation service).
15:15:57.920 If you are installing with npm, you can try ensuring that both npm and node are
15:15:57.920 not running under Rosetta 2 and then reinstalling esbuild. This likely involves
15:15:57.920 changing how you installed npm and/or node. For example, installing node with
15:15:57.920 the universal installer here should work: https://nodejs.org/en/download/. Or
15:15:57.921 you could consider using yarn instead of npm which has built-in support for
15:15:57.921 installing a package on multiple platforms simultaneously.
15:15:57.921 If you are installing with yarn, you can try listing both "arm64" and "x64"
15:15:57.921 in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
15:15:57.921 https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
15:15:57.921 Keep in mind that this means multiple copies of esbuild will be present.
15:15:57.921 Another alternative is to use the "esbuild-wasm" package instead, which works
15:15:57.921 the same way on all platforms. But it comes with a heavy performance cost and
15:15:57.921 can sometimes be 10x slower than the "esbuild" package, so you may also not
15:15:57.921 want to do that.
15:15:57.921 at generateBinPath (/Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/esbuild/lib/main.js:1874:17)
15:15:57.921 at esbuildCommandAndArgs (/Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/esbuild/lib/main.js:1955:33)
15:15:57.921 at ensureServiceIsRunning (/Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/esbuild/lib/main.js:2119:25)
15:15:57.921 at build (/Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/esbuild/lib/main.js:2011:26)
15:15:57.921 at bundleConfigFile (file:///Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:64337:26)
15:15:57.921 at loadConfigFromFile (file:///Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:64313:31)
15:15:57.921 at resolveConfig (file:///Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:63922:34)
15:15:57.921 at _createServer (file:///Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:63206:26)
15:15:57.921 at Module.createServer (file:///Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/dist/node/chunks/dep-934dbc7c.js:63203:12)
15:15:57.921 at /Users/xxx/Desktop/dmeo/my-vue3-project/node_modules/vite/index.cjs:23:55
15:15:57.921 已停止运行...
bug描述:
按照官方示例创建Vue3/Vite cli工程:
npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
启动H5项目时报错
更多关于uni-app Mac系统下cli项目无法编译启动的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app Mac系统下cli项目无法编译启动的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在 Mac 系统下使用 uni-app CLI 项目时,如果遇到无法编译启动的问题,可能由多种原因引起。以下是一些常见的排查和解决方法:
1. 检查 Node.js 和 npm 版本
- uni-app 需要 Node.js 和 npm 的支持,请确保已安装并配置正确。
- 推荐使用 LTS 版本的 Node.js(如 16.x 或 18.x),可以通过以下命令检查:
node -v npm -v - 如果版本过低或过高,可以通过
nvm(Node Version Manager)来管理 Node.js 版本:nvm install 16 nvm use 16
2. 清理 npm 缓存
- 有时 npm 缓存可能导致问题,可以尝试清理缓存并重新安装依赖:
npm cache clean --force rm -rf node_modules npm install
3. 检查项目依赖
- 确保项目依赖已正确安装,进入项目根目录,运行:
npm install - 如果安装过程中出现错误,可能是某些依赖包不兼容,可以尝试更新依赖:
npm update
4. 检查 HBuilderX CLI
- 如果使用 HBuilderX CLI,请确保已正确安装并配置:
npm install -g @vue/cli @vue/cli-service-global - 如果 HBuilderX CLI 版本过低,可以尝试更新:
npm update -g @vue/cli
5. 检查环境变量
- 确保系统环境变量配置正确,尤其是
PATH中是否包含 Node.js 和 npm 的路径。 - 可以通过以下命令查看:
echo $PATH - 如果缺少路径,可以手动添加:
export PATH=$PATH:/usr/local/bin
6. 查看错误日志
- 运行编译命令时,查看终端输出的错误信息,通常会有具体的提示。
- 例如,运行以下命令:
其中npm run dev:%PLATFORM%%PLATFORM%是目标平台(如h5、mp-weixin等)。
7. 检查项目配置
- 确保
package.json中的脚本配置正确,例如:"scripts": { "dev:h5": "uni -p h5", "build:h5": "uni -p h5 --mode production" } - 如果配置有误,可能会导致无法启动。
8. 检查权限问题
- Mac 系统有时会限制对某些目录的访问权限,确保项目目录有足够的权限:
sudo chmod -R 777 /path/to/your/project
9. 尝试重新创建项目
- 如果以上方法无效,可以尝试重新创建一个 uni-app 项目:
npx degit dcloudio/uni-preset-vue#vite my-project cd my-project npm install npm run dev:%PLATFORM%
10. 更新 uni-app 版本
- 如果使用的是较旧的 uni-app 版本,可能存在兼容性问题,可以尝试更新:
npm install -g @dcloudio/uni-cli

