Skip to content

window.p5._report is not defined #2327

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

Closed
quinton-ashley opened this issue Jul 25, 2023 · 3 comments · Fixed by #2426
Closed

window.p5._report is not defined #2327

quinton-ashley opened this issue Jul 25, 2023 · 3 comments · Fixed by #2426
Labels

Comments

@quinton-ashley
Copy link

quinton-ashley commented Jul 25, 2023

p5.js version

v1.7.0

What is your operating system?

Mac OS

Web browser and version

114.0.5735.198 (Official Build) (arm64)

Actual Behavior

Only when using the p5.js web editor I get an error saying _report is not defined at undefined.

It's on line 105 of previewEntry.js

// Monkeypatch p5._friendlyError
const { _report } = window.p5;

It seems window.p5 doesn't exist at that point.

Expected Behavior

No errors.

Steps to reproduce

Press play to see the error show up in the console:

https://editor.p5js.org/quinton-ashley/sketches/B9bcs2HOK

Working example with no errors:

https://editor.p5js.org/quinton-ashley/sketches/aRSwZGkfg

@quinton-ashley
Copy link
Author

@davepagurek said that the error was caused by my script tags being at the end of the body tag and not inside the head tag of my html. The fix was simple, I just moved the tags.

If I'm not mistaken though, it's pretty typical to add script tags at the end of the body tag, so this issue should still be fixed imo.

@lindapaiste
Copy link
Collaborator

lindapaiste commented Jul 28, 2023

Interesting! That previewEntry.js file where the error is gets built into a file previewScripts.js. It is definitely injected into the <head>. We could potentially move it to the end of the <body> to ensure that the code which loads p5 is always called first.

Here's where we add it to the <head>.

const previewScripts = sketchDoc.createElement('script');
previewScripts.src = `${window.location.origin}${getConfig(
'PREVIEW_SCRIPTS_URL'
)}`;
previewScripts.setAttribute('crossorigin', '');
sketchDoc.head.appendChild(previewScripts);

@Ankush263
Copy link
Contributor

Hey @lindapaiste, I solved this issue locally. I'm going to open a PR for this 🧑‍💻

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

Successfully merging a pull request may close this issue.

4 participants