Hey @aitor - once you install p5 with yarn, you can do this to import it:
import p5 from "p5";
But this is a huge import (check the output from yarn build
, so this might be better:
import p5 from "p5/lib/p5.min";
You will still see ‘Uncaught ReferenceError: p5 is not defined.’ if you enter p5 in the console, because when you import it this way it’s not placed in the global scope. If you put console.log(p5)
after your import, you should see a better result.
TBH from my research/testing on this it seemed like p5 may not be set up the best for importing (and it’s not something they document anywhere that I can find). Although that’s normally the method I would recommend, if you run into much more trouble going about it this way it may be best to switch to the “manual” method you were also trying.
That said, if you Google there are some examples of people loading it this way, and you may be able to learn from them. For example: https://github.com/vilvadot/p5-tests
PS - when you’re importing a js file you don’t have to add the .js at the end.