I copied example code into my editor, saved and it does not work (surprise :) )
I had to alter it, so as it works as expected and I have absolutely no idea, why it works after i had altered it.
I followed a http://browserify.org/ tutorial.
main.js is for me
require.config({
paths: {
"uniq": "../node_modules/uniq/uniq"
}
});
define(function (require) {
var unique = require('uniq');
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
console.log(unique(data));
});
This is uniq.js one I altered: http://paste2.org/5465mVUF
The original one: http://paste2.org/wY7wP6pB
The only thing I did was i wrapped all uniq.js code inside anonymous function within a define() wrapper
define(function (require, exports, module) {
//uniq.js code here...
});
My questions is why? What I did do wrong?
You must decide to use only one module loader: browserify or requirejs. You cannot use both.
When You want to use browserify
then don't use define
, require.config
.
When You want to use requirejs
then don't use nodejs
packages. Use browser-specific packages from e.g. bower
.