I am very new to javascript and even more to ES modules. However, I think I am trying things out correctly here. But as I am not sure if I am doing things right, I first drop a question here before I report an issue at either jsdeliver or p5. My final question will be: is this a bug, or am I doing things wrong?
I am trying to use the p5 via cdn as esm from jsdeliver. However, when trying to load my html, the console reports
jsdelivr-header.js:7 Uncaught SyntaxError: The requested module '/npm/@davepagurek/[email protected]/+esm' does not provide an export named 'createFromCommands' (at jsdelivr-header.js:7:1)
as far as I could find in here in the bezier-path source, the createFromCommands command does get exported (but again I am totally new to modules, so I am not sure if my conclusion is right).
As I am not sure how to use esm modules, I asked āGemini AIā for a usage example. Trying to use that example results in the same error.
Here is my html
p5.js ESM from jsDelivr Example
So now again my question, is the above described behavior due to a bug or me doing things the wrong way?
A JS script using type āmoduleā doesnāt behave the same way as a regular 1.
1 of its many āgotchasā is related to declaring variables using keywords var & function.
For example, your 2 functions function setup() {} & function draw() {} will have different global visibility depending on whether theyāre being run using type āmoduleā or not!
For regular JS script type, the variable declaring keyword function (and var as well) will also append the variables setup & draw on the globalThis:
However, for type āmoduleā, that wonāt happen!
B/c neither setup() nor draw() callbacks are present on globalThis, p5js wonāt āseeā them; and thus your sketch wonāt run!
As a workaround, you can manually add those 2 function variables as globalThis properties:
That is very useful information, I would be one step closer to getting the āmoduleā setup to work. Just, I still need to get rid of that error message when trying to use the āesmā library.
I guess, there is something wrong with that āesmā package on jsdeliver, but I am not sure (how it should work). Anyway, after getting it āimportedā I will be aware of your āadviceā. Thank you very much for this explanation