Browserify to require NPM Modules

Thanks for the detailed info. Have you already worked with browserify before? The idea is that you add all the dependencies in package.json (this case p5.js - note that the npm module is called “p5”). Bundling the sketch without p5 might work but not the way how it is intended.

I imported your project and made it working here - check package.json and app/sketch.js

The problem is that it seems p5.js as a module does not support global mode (more here). When I copied the instance-mode code from the link it works fine. I’m not sure if there is a way to make global mode here, but generally I would recommend switching to instance mode if you are using npm/browserify because weird things can happen around the namespace.

1 Like