While @javagar 's post shows how to make it work, it’s not a solution to javascript import/export. I can explain a bit about modules, but in short, I don’t suggest to use p5.js with javascript modules because it’s too complicated.
The way how it works is you need to add type="module" when importing the script (and as javagar suggested, you need to call the function pointCoord() in draw).
<script src="sketch.js" type="module"></script>
However, this code won’t work in your case because p5.js is not properly loaded when the script is loaded as a module. Also, your module pointCoord depends on p5.js, so that the module has to load p5.js as well
I think the only way to make this work is to write everything in instance mode and use tools like browserify to add p5.js dependency to your pointCoord module. I know this is ridiculous, but since p5.js (global mode) itself is a “hack”, sadly it won’t work out of the box with features like JS modules.
nice! I guess you are passing the p5 instance as an argument to the modules, right? I guess this is the most straightforward way although you have to stick to the instance mode.
I see! So it’s in the global mode but you need to reference the instance. Also setup / draw has to be defined as a member of window to be picked up by p5.js. Based on your code I adapted the OP’s code:
That’s right! A JS module got 2 global contexts: A private 1 and a shared 1.
Explicitly appending to window or globalThis assures those properties can be accessed by both vanilla & module scripts which are sharing the same global context.