-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[p5.js 2.0 Beta Bug Report]: Output a friendly error when p5 is loaded twice on a page #7687
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
Comments
@davepagurek can i give it a try |
Sure thing @VANSH3104, even without a fix yet, let me know in a comment here if you can figure out what the cause is! Now that we've started testing out a beta site for 2.0, you can see this happening for yourself at e.g. https://beta.p5js.org/reference/p5/arc/ and looking in your browser console. |
@davepagurek I checked it out in the browser console, and it seems like the issue is related to how width is defined. The error Uncaught TypeError: can't redefine non-configurable property "width" suggests that width might already be locked, possibly by another script or browser restrictions. I also noticed multiple instances of p5.js being loaded, which I think could be causing conflicts. |
Thanks @VANSH3104! I think you're right, the script tag is getting included multiple times on the reference page, which I can see in the browser's element inspector dev tools: ![]() So I think there are actually two problems going on here:
|
I renamed this issue and made an issue for the website repo here: processing/p5.js-website#770 |
More context on the issue here:
So I think we maybe need to update it to look for a different variable that we can set immediately once we know we're in global mode. Maybe we make a |
@davepagurek Have you found anything else on the double-initialization issue? The changes window._p5Initialized don’t seem to work as expected. |
@VANSH3104 I haven't tried it out myself, if you've started and want some help debugging feel free to open a draft PR and I can take a look! |
The error logged is because When p5.js is loaded multiple times, the global initialization is called multiple times, ie. fulfilling the error condition above. In 1.x there are checks to prevent multiple initialization I think but I must have accidentally removed it if it existed. We can reimplement it by checking for the existence of |
Most appropriate sub-area of p5.js?
p5.js version
2.0 beta 5
Web browser and version
Firefox
Operating system
MacOS
Steps to reproduce this
Steps:
npm run dev
You see this error in the console

Not sure what the cause is just yet. Doesn't seem to affect the examples though.
The text was updated successfully, but these errors were encountered: