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

升级Cordova CLI12与iOS7后自定义插件安装报错求助

升级Cordova CLI 12 + iOS 7后添加自定义插件报错解决

问题场景

升级Cordova CLI到12版本、Cordova iOS到7版本后,执行以下添加自定义插件命令时出错:

cordova plugins add ../../cordova-custom-plugins/DIMScanner/DimScannerCordovaPlugin/

报错信息

Plugin "cordova-plugin-dimscanner" already installed on android.
Installing "cordova-plugin-dimscanner" for ios
Error during processing of action! Attempting to revert...
Failed to install 'cordova-plugin-dimscanner': TypeError [ERR_INVALID_ARG_TYPE]: Uh oh!
The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:399:5)
    at validateString (node:internal/validators:163:11)
    at Object.basename (node:path:1313:5)
    at new pbxFile (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/xcode/lib/pbxFile.js:189:26)
    at pbxProject.addBuildPhase (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/xcode/lib/pbxProject.js:921:26)
    at install (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/cordova-ios/lib/plugman/pluginHandlers.js:124:31)
    at ActionStack.process (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/cordova-ios/node_modules/cordova-common/src/ActionStack.js:55:25)
    at PluginManager.doOperation (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/cordova-ios/node_modules/cordova-common/src/PluginManager.js:111:24)
    at PluginManager.addPlugin (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/cordova-ios/node_modules/cordova-common/src/PluginManager.js:141:21)
    at Api.addPlugin (/Users/patrick/VMSharedFolder/Projects/newgesmobile/gesmobile/src-cordova/node_modules/cordova-ios/lib/Api.js:258:14)
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('ERR_INVALID_ARG_TYPE')
    at process.set [as exitCode] (node:internal/bootstrap/node:124:9)
    at /usr/local/lib/node_modules/cordova/bin/cordova:32:22

自定义插件plugin.xml内容

<plugin id="cordova-plugin-dimscanner" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>DIMScanner</name>
<js-module name="DIMScanner" src="www/DIMScanner.js">
    <clobbers target="cordova.plugins.DIMScanner" />
</js-module>
<platform name="ios">
    <config-file parent="/*" target="config.xml">
        <feature name="DIMScanner">
            <param name="ios-package" value="DIMScanner" />
        </feature>
    </config-file>
     <preference name="CAMERA_USAGE_DESCRIPTION" default="This app needs camera access"/>
        <config-file target="*-Info.plist" parent="NSCameraUsageDescription">
            <string>$CAMERA_USAGE_DESCRIPTION</string>
         </config-file>
     <preference name="PHOTO_LIBRARY_USAGE_DESCRIPTION" default="This app needs to access photo library"/>
    <config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
        <string>$PHOTO_LIBRARY_USAGE_DESCRIPTION</string>
     </config-file>
    <source-file src="src/ios/DIMScanner.swift" />
    <framework src="src/ios/DimScannerFramework.framework" custom="true" embed="true"/>
      <podspec>
         <config>

         </config>
         <pods use-frameworks="true">
             <pod name="Alamofire" tag="5.0.0-rc.3" git="https://github.com/Alamofire/Alamofire.git" />
             <pod name="SnapKit"/>
             <pod name="PKHUD" tag="5.3.0" git="https://github.com/pkluz/PKHUD.git"/>
             <pod name="Firebase/MLVisionTextModel"/>
         </pods>
        </podspec>
</platform>

解决方案

从报错栈分析,问题出在pbxFile初始化时收到了undefined的路径参数,根源是Cordova iOS 7对自定义框架的处理逻辑有更新,按以下步骤调整:

  • 修正自定义框架声明:给<framework>标签添加framework属性指定框架名称,确保Cordova能正确识别框架:
    修改原框架声明行:

    <framework src="src/ios/DimScannerFramework.framework" custom="true" embed="true" framework="DimScannerFramework"/>
    
  • 检查框架文件完整性:确认插件目录下src/ios/DimScannerFramework.framework路径正确,且框架文件完整(包含Headers、Modules等必要子目录)

  • 配置Swift版本:Cordova iOS 7对Swift插件的版本适配要求更严格,在plugin.xml的iOS平台节点下添加Swift版本声明:

    <preference name="UseSwiftLanguageVersion" value="5"/>
    
  • 清理后重新安装插件:先卸载已有插件,清理缓存后重新添加:

    cordova plugin remove cordova-plugin-dimscanner
    rm -rf node_modules/ package-lock.json
    npm install
    cordova plugins add ../../cordova-custom-plugins/DIMScanner/DimScannerCordovaPlugin/
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 00:27:13