Hi im doing this test to import a class from a separate file:
but i got error:
The export:
The import:
The html file:
Any help would be apreciated
This is for educational purpose
Hi im doing this test to import a class from a separate file:
but i got error:
The export:
The import:
The html file:
Any help would be apreciated
This is for educational purpose
Do you have to use āmoduleā? I added this line to index.html
<script src="Pacman.js"></script>
and did not place the file in a folder. I also removed the word āexportā before class Pacman{ā¦}
I used this code without import
let myPacman = new Pacman(100,100);
console.log(Pacman);
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
myPacman.showPacman();
}
It worked and I got this output:
Also got it, but i need inside folder classes, as id have more classes and i want the project some kind of order.
In JS all files that has any import/export should be modules.
Also import and export should be as all JS works this way.
I think import/export doesnt work in p5.jsā¦dont know if its a bug, or is not implemented yet, or you have to import/export like you did @svanā¦
Thanks, hope anybody specially dev could give a light in the darkness.
Those 2 keywords are JS features, and p5.js, which is a frontend library, canāt change that:
As I have already mentioned to you on your previous forum thread:
B/c they donāt even acknowledge ECMA Script Modules (ESM / ā.mjsā) exist anywhere on their docs, itās no wonder their āp5.js Web Editorā doesnāt seem to be compatible w/ ESM either!
Pretty much any other JS code hosting/editor solution available should work!
For example, you can try out:
And many others to host JS code + p5.js library!
Thanks for sharing your thoughts! p5.js and the p5.js web editor are open-source projects built and maintained by the community. If thereās a feature youād like to see or something that could be improved, Iād encourage you to open an issue on the p5.js repository or the p5.js web editor repository on GitHub, or even contribute a code change. Your feedback and contributions are what help these projects grow and evolve