Browserify to require NPM Modules

Hi @micuat,

I’ve pushed the test file I was working on, to git here: GitHub - diogorsergio/p5-test
Can you have a look? To see if you can see whats happening? It would be really appreciated.

I was trying to use the require method to load a npm module nice-color-palettes.
So when the p5 skech was working what I did was:

  1. npm init
  2. npm install nice-color-palettes sketch.js is already requiring it.
  3. npm install --global browserify
  4. browserify sketch.js > bundle.js

After

  1. Change index.html to load bundle.js instead of sketch.js.
    • It loads the npm module sucessfuly, console is logging the array that it returns of colors, but the original sketch fails to load on the page.
  2. Change index.html back to sketch.js
    • Npm module fails sketch.js:1 Uncaught ReferenceError: require is not defined, but now the sketch loads ok.

Thanks!

1 Like