voxel / voxel-plugins

an API for loading and enabling plugins in voxel.js with soft dependencies
https://github.com/deathcap/voxel-plugins/wiki
9 stars 2 forks source link

Getting undefined is not a function error when adding plugins #3

Closed quorth0n closed 8 years ago

quorth0n commented 10 years ago

Hello all, When I try calling plugins.add, I get the following error: Uncaught TypeError: undefined is not a function Here is my code:

var createPlugins = require('voxel-plugins');
var plugins = createPlugins(game, {require:require});

//Load Plugins
plugins.add('voxel-health', {maxHealth: 20});
plugins.add('voxel-health-bar', {});
plugins.loadAll();

The error occurs where I attempt to add the voxel-health and the voxel-health-bar plugins.

Thank you all in advanced

deathcap commented 8 years ago

When using the require:require option, plugins have to be require()'d in the calling module before using plugins.add(), something like this:

require('voxel-health');
require('voxel-health-bar');
var createPlugins = require('voxel-plugins');
var plugins = createPlugins(game, {require:require});

//Load Plugins
plugins.add('voxel-health', {maxHealth: 20});
plugins.add('voxel-health-bar', {});
plugins.loadAll();

if you still see this when adding the require()s, could you include the full stacktrace for the "Uncaught TypeError: undefined is not a function" error.

In voxel-plugins 0.5.0+ (https://github.com/voxel/voxel-plugins/issues/8), added a new 'loaders' option which makes the dependencies clearer:

var createPlugins = require('voxel-plugins');
var plugins = createPlugins(game, {loaders:
  'voxel-health': require('voxel-health'),
  'voxel-health-bar': require('voxel-health-bar')
});

//Load Plugins
plugins.add('voxel-health', {maxHealth: 20});
plugins.add('voxel-health-bar', {});
plugins.loadAll();