Cordova插件错误:“未捕获的模块......已定义”

时间:2020-12-01 20:28:42

I was getting the following error and my custom plugin wasn't starting.

我收到以下错误,我的自定义插件没有启动。

"Uncaught module com.example.example-plugin already defined"

“未定义的模块com.example.example-plugin已定义”

Why is my module getting defined twice?

为什么我的模块定义了两次?

2 个解决方案

#1


13  

This error occurred because I copy-pasted code from the generated 'example-plugin.js' back into the original plugin file.

发生此错误是因为我将生成的'example-plugin.js'中的代码复制粘贴回原始插件文件。

When I added the plugin again, the generated code then got wrapped twice like this:

当我再次添加插件时,生成的代码然后被包装两次,如下所示:

cordova.define("com.example.example-plugin", function(require, exports, module) { cordova.define("com.example.example-plugin", function(require, exports, module) { var exec = require('cordova/exec');

cordova.define(“com.example.example-plugin”,function(require,exports,module){cordova.define(“com.example.example-plugin”,function(require,exports,module){var exec = require ( '科尔多瓦/ EXEC');

Removing the generated bits from the original example-plugin.js file fixed this.

从原始example-plugin.js文件中删除生成的位修复了这个问题。

#2


2  

Just to expand on akiraspeirs answer. The 'example-plugin.js' file is located in the Android folder under Assets/www/plugins/example-plugin/example-plugin.js

只是为了扩展akiraspeirs的答案。 'example-plugin.js'文件位于Assets / www / plugins / example-plugin / example-plugin.js下的Android文件夹中

#1


13  

This error occurred because I copy-pasted code from the generated 'example-plugin.js' back into the original plugin file.

发生此错误是因为我将生成的'example-plugin.js'中的代码复制粘贴回原始插件文件。

When I added the plugin again, the generated code then got wrapped twice like this:

当我再次添加插件时,生成的代码然后被包装两次,如下所示:

cordova.define("com.example.example-plugin", function(require, exports, module) { cordova.define("com.example.example-plugin", function(require, exports, module) { var exec = require('cordova/exec');

cordova.define(“com.example.example-plugin”,function(require,exports,module){cordova.define(“com.example.example-plugin”,function(require,exports,module){var exec = require ( '科尔多瓦/ EXEC');

Removing the generated bits from the original example-plugin.js file fixed this.

从原始example-plugin.js文件中删除生成的位修复了这个问题。

#2


2  

Just to expand on akiraspeirs answer. The 'example-plugin.js' file is located in the Android folder under Assets/www/plugins/example-plugin/example-plugin.js

只是为了扩展akiraspeirs的答案。 'example-plugin.js'文件位于Assets / www / plugins / example-plugin / example-plugin.js下的Android文件夹中