我们正在同一个组织下开发几个NPM包:
@aerogearservices/core @aerogearservices/core-rn @aerogearservices/core-cordova
其中core-cordova是Cordova插件,通过依赖项安装(阅读更多关于scoped packages).
相关文件:
App的package.json
{ ... "dependencies": { "@aerogearservices/core-cordova": "1.0.0",... },"cordova": { "plugins": {},"platforms": ["ios","android"] } }
插件的package.json
{ "name": "@aerogearservices/core-cordova","version": "1.0.0",... "cordova": { "id": "aerogearservices-core-cordova","platforms": [ "android" ] },"dependencies": { "@aerogearservices/core": "1.0.0" },"engines": { "cordovaDependencies": { ... } } }
插件的plugin.xml
…
…
Apache 2.0
<platform name="android"> <config-file target="res/xml/config.xml" parent="/*"> ... </config-file> <source-file ... /> </platform>
该插件真的什么也没做,我只是想在我的应用程序中安装它,但当我运行cordova平台添加android我得到这个错误:
UnhandledPromiseRejectionWarning: CordovaError: Cannot find plugin.xml for plugin "@aerogearservices". Please try adding it again.
问题是Cordova在myApp / plugins / aerogearservices / core-cordova下安装了插件,因此它在错误的位置寻找plugin.xml.
解决方法
它可能不是你的问题的解决方案,但我最终在创建一个scoped npm注册表中发布的cordova插件时出现问题,这就是我设法解决它的方法:
插件的config.xml不应该提到范围:
<plugin id="cordova-plugin-myplugin" ...> <name>cordova-plugin-myplugin</name>
另一方面,插件的package.json应该提到它:
"name": "@scope/cordova-plugin-myplugin","cordova": { "id": "@scope/cordova-plugin-myplugin","platforms": [ "android","windows","ios" ] },
现在,我没有问题
cordova plugin add @scope/cordova-plugin-myplugin
我希望这可能真的有助于某人