Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access init function using browserify #217

Closed
najajan-de opened this issue Mar 7, 2022 · 4 comments
Closed

Can't access init function using browserify #217

najajan-de opened this issue Mar 7, 2022 · 4 comments
Assignees
Labels

Comments

@najajan-de
Copy link

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

@cesalberca
Copy link

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.

@ianstormtaylor
Copy link

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?

@zenozeng zenozeng self-assigned this May 8, 2022
@zenozeng zenozeng added the bug label May 8, 2022
zenozeng added a commit that referenced this issue May 8, 2022
zenozeng added a commit that referenced this issue May 8, 2022
@zenozeng
Copy link
Owner

zenozeng commented May 8, 2022

@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 zenozeng closed this as completed May 8, 2022
@ianstormtaylor
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants