新 M1 macs 的 ionic cordova 本地插件错误

时间:2021-01-22 00:07:25

标签: cordova ionic-framework ionic3 ionic4 cordova-plugins

我们有一些使用添加的本地插件 离子cordova插件添加./cordova-plugin-name

在 intel mac 上构建时它们工作正常,但在带有 Big Sur 的新 M1 mac 中构建项目时出现以下错误

Discovered saved plugin "cordova-plugin-ionic-keyboard". Adding it to the project
Installing "cordova-plugin-ionic-keyboard" for ios
Adding cordova-plugin-ionic-keyboard to package.json
Discovered saved plugin "cordova-plugin-iovation". Adding it to the project
Failed to restore plugin "cordova-plugin-iovation" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin file:scripts/plugin/cordova-plugin-iovation via registry. Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR!
Cannot read property 'match' of undefined
npm ERR!
npm ERR!
Discovered saved plugin "cordova-plugin-advanced-http". Adding it to the project
Failed to restore plugin "cordova-plugin-advanced-http" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin file:scripts/plugin/cordova-plugin-advanced-http via re gistry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR!
Cannot read property 'match' of undefined
A complete log of this run can be found in: /Users/xx/.npm/_logs/2021-01-21T12_29_50_477Z-debug.log
npm ERR!
npm ERR!
Discovered saved plugin "call-number". Adding it to the project
Installing "mx.ferreyra.callnumber" for ios
Adding mx.ferreyra.callnumber to package.json
Discovered saved plugin "cordova-plugin-app-version". Adding it
Installing "cordova-plugin-app-version" for ios

这是一个已知问题吗?我该如何解决?

1 个答案:

答案 0 :(得分:1)

看起来 CLI 不知道这些是本地插件,因此它尝试从注册表下载它们。这很可能是 npm 问题。使用cordova 和npm 7 的东西不太好。我建议你运行node v15.6.0(最新的非lts)。

此版本通常与较新的 npm (v7) 捆绑在一起,但是要使其正常工作(直到cordova 整理它们的内容),您必须将 npm 降级到 6.14.11

我已经这样做了(是否使用 sudo 取决于您的环境设置):

sudo npm i -g npm

或者你可以指定一个版本:

sudo npm i -g npm@version

上述解决方案的来源: https://github.com/apache/cordova-cli/issues/541

除此之外,我只需要争取几个小时就可以在我的 M1 上构建东西......

一些可能会对您有很大帮助的提示:

  • Cocoapods 需要安装在 rosetta 模式终端中。在安装 cocoapods 并在 ios 平台文件夹中运行 pod install 之前,您很可能需要在同一个终端中安装 ffi gem。默认情况下,本地 ffi gem 似乎不适用于 cocoapods。
  • 您将不得不在 XCode 中自动构建 arm64 和 x86_64 架构模拟器。如果不这样做,您将在构建时遇到符号丢失错误。

更新:看起来cordova 现在已经通过整理它们的依赖项来解决这个问题。卸载并重新安装cordova 应该会获得它与最新的稳定npm 一起工作所需的所有包