【发布时间】:2018-03-06 07:20:31
【问题描述】:
我有一个标准的 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。
【问题讨论】:
标签: cordova npm cordova-plugins