You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook Pro M2环境下Node.js18.15.0安装Ionic项目报错求助

解决Ionic创建Angular项目时@angular/router版本错误的问题

问题根源

你遇到的错误大概率是全局Ionic未正确安装、Node版本与Angular版本不匹配,或是M2芯片架构下npm包拉取异常导致的。以下是具体解决步骤:

步骤1:清理并重装全局依赖

先彻底清理旧的全局包缓存,重新安装兼容的Ionic和Angular CLI:

npm uninstall -g ionic @angular/cli
npm cache clean --force
npm install -g @angular/cli@latest ionic@latest

步骤2:创建项目时指定兼容的Angular版本

Node.js 18.15.0(LTS)兼容Angular 14.x到17.x版本,创建项目时明确指定版本可避免依赖拉取错误:

ionic start myApp blank --type=angular --angular-version=15.2.9

(也可以选择16.x或17.x的稳定版,根据需求调整)

步骤3:适配M2芯片架构

M2是arm64架构,需要确保npm使用对应架构的包:

  1. 检查当前npm架构:
npm config get arch
  1. 如果输出是x64,执行以下命令切换为arm64:
npm config set arch arm64
  1. 确保安装了Xcode命令行工具(部分依赖编译需要):
xcode-select --install

步骤4:手动初始化项目(备选方案)

如果上述方法仍无效,可先创建纯净Angular项目再集成Ionic:

# 创建Angular项目(开启路由,使用scss样式)
ng new myApp --style=scss --routing=true
cd myApp
# 初始化Ionic配置
ionic init --type=angular
# 安装Ionic Angular依赖
npm install @ionic/angular @ionic/angular-toolkit

内容的提问来源于stack exchange,提问作者Yann92

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 07:53:21