14

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

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

Why is my module getting defined twice?

akiraspeirs
  • 2,127
  • 2
  • 21
  • 29

3 Answers3

24

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

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');

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

akiraspeirs
  • 2,127
  • 2
  • 21
  • 29
6

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

Noman
  • 887
  • 1
  • 15
  • 34
3

To expand on the 2 above answers. Deleting the www folder & platforms/browser -if running on browser. Then running ionic cordova prepare browser built all files again correctly.

Zahema
  • 1,345
  • 2
  • 19
  • 35