zenozeng / p5.js-svg

SVG runtime for p5.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't access init function using browserify

najajan-de opened this issue · comments

I'm using import p5Svg from 'p5.js-svg'; and p5Svg(p5); in my project.
After packing with browserify, I'm getting this in the browser console: Uncaught TypeError: (0 , p5_js_svg_1.default) is not a function

I figured out, that theres no module.export in p5.svg.js, so I added it on the begin of the file. With

module.exports = (function () {
...
return init;
});

it works just fine, so maybe you could consider to add this.

I don't know if there's another way to access the function outside module.exports

This is also happening to me. Maybe it has to do with the way rollup bundles the code? Perhaps rollup should generate multiple bundles in order to avoid this issue. I'm using https://www.npmjs.com/package/patch-package in the meantime as a workaround by adding the module.exports manually.

I'm running into the same issue, except using Vite instead of Browserify. I'm not sure if the code as written would work in any bundler?

@najajan-de @cesalberca @ianstormtaylor

Hi, this bug should be fixed in v1.3.3. I added cjs output in rollup.config.js.

BTW examples for Webpack and vite were also added:

@zenozeng thank you, that worked on the first try! You are amazing!