本地Cordova插件的位置和配置?

时间:2018-03-05 19:28:47

标签: cordova npm cordova-plugins

我有一个标准的Cordova项目,如下所示:

build.json
config.xml
hooks/
my-custom-plugin/
  src/
  www/
  package.json
  plugin.xml
package-lock.json
package.json
res/
www/

我写了一个自定义插件,我将其保存在项目的子目录中。我将它添加到我的Cordova项目中:

cordova plugin add my-custom-plugin

它将以下内容添加到config.xml

<plugin name="my-custom-plugin" spec="my-custom-plugin" />

和package.json:

"dependencies": {
    "my-custom-plugin": "file:my-custom-plugin"

我不想将node_modules/plugins/platforms/提交给SCM;我想让Cordova在构建过程中重新创建它们。

但是当我查看上面的项目并运行cordova prepare --verbose时,它会给我一个错误:

Failed to restore plugin "my-custom-plugin" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin my-custom-plugin@file:my-custom-plugin 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! code ENOLOCAL
npm ERR! Could not install from "my-custom-plugin" as it does not contain a package.json file.

(最后一条消息不正确;如上所示,它确实包含一个有效的package.json文件。)

详细的错误日志包含:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli   '/usr/bin/npm',
1 verbose cli   'install',
1 verbose cli   'my-custom-plugin@file:my-custom-plugin' ]
2 info using npm@5.6.0
3 info using node@v8.9.4
4 verbose npm-session 2b51ee3ccee75e63
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData error for my-custom-plugin@file:my-custom-plugin Could not install from "my-custom-plugin" as it does not contain a package.json file.
8 verbose stack Error: ENOENT: no such file or directory, open '/my-project/node_modules/my-custom-plugin/package.json'
9 verbose cwd /my-project/node_modules
10 verbose Linux 3.10.0-514.21.1.el7.x86_64
11 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "my-custom-plugin@file:my-custom-plugin"
12 verbose node v8.9.4
13 verbose npm  v5.6.0
14 error code ENOLOCAL
15 error Could not install from "my-custom-plugin" as it does not contain a package.json file.
16 verbose exit [ 1, true ]

如果我首先尝试运行npm install,那么该命令可以正常工作,但cordova prepare命令仍会失败并出现相同的错误。

这样做的正确方法是什么?

我在MacOS和Linux上都使用了cordova-cli 8.0.0,节点8.9.4。

1 个答案:

答案 0 :(得分:1)

这是一个错误,已经有报道了 https://issues.apache.org/jira/browse/CB-13801