Ionic Cordova添加iOS平台失败,求助解决方案
Hey there, let's break down each of these issues and walk through how to fix them step by step—this stuff can be tricky when you're new to Ionic/Cordova, but we'll get you sorted.
requireCordovaModule加载非Cordova模块(q/glob)的错误 Here's what's happening: Starting with Cordova 9, the team restricted the use of requireCordovaModule to only load official Cordova core modules. Older versions of plugins like cordova-sqlite-storage and cordova-plugin-statusbar still use this method to load third-party modules (like q or glob), which triggers the error.
Fixes:
- Update the plugins to their latest versions (most modern plugin versions have fixed this issue):
First uninstall the old plugins, then install the latest stable builds:# Remove outdated plugins ionic cordova plugin remove cordova-sqlite-storage ionic cordova plugin remove cordova-plugin-statusbar # Install latest versions ionic cordova plugin add cordova-sqlite-storage@latest ionic cordova plugin add cordova-plugin-statusbar@latest - Temporary workaround (if updates don't help):
If a plugin hasn't been updated to fix this, you can add a preference toconfig.xmlto bypass the restriction (note: this isn't ideal long-term, but it works for immediate builds):
Add this line either inside the<platform name="ios">tag or globally in yourconfig.xml:<preference name="AllowCordovaModule" value="true" />
This is a version compatibility issue. Node.js runtime version 72 corresponds to Node.js 12.x, and your installed Node Sass version doesn't support this Node.js release. Node Sass has been deprecated in favor of Dart Sass, so here are your options:
Fixes:
- Option 1: Install a Node Sass version compatible with Node.js 12.x:
Node.js 12 works with Node Sass versions 4.12.x to 4.14.x. Uninstall your current Node Sass and install a matching version:npm uninstall node-sass npm install node-sass@4.14.1 --save-dev - Option 2: Switch to Dart Sass (Recommended):
Dart Sass is the official replacement for Node Sass and has better long-term support. Uninstall Node Sass and install Dart Sass instead:
Your project will automatically use Dart Sass for compilation—no extra configuration needed, and it's compatible with most existing Sass code.npm uninstall node-sass npm install sass --save-dev
glob error This is usually due to cached old plugin files or leftover dependencies. A "clean slate" reinstall often fixes this:
Steps:
- Clean Cordova's build cache:
cordova clean ios - Clear npm's cache:
npm cache clean --force - Delete all dependency and platform/plugin folders to start fresh:
rm -rf node_modules package-lock.json platforms plugins - Reinstall npm dependencies, add the iOS platform, and reinstall the updated plugins:
npm install ionic cordova platform add ios ionic cordova plugin add cordova-sqlite-storage@latest cordova-plugin-statusbar@latest
After completing these steps, try running your build command again:
ionic cordova build ios --prod
内容的提问来源于stack exchange,提问作者Premox




