Hello,
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/bezier-path@0.0.2/+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
<!DOCTYPE html>
<html>
<head>
<title>p5.js ESM from jsDelivr Example</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script type="module">
import p5 from 'https://cdn.jsdelivr.net/npm/p5@2.0.1/+esm';
let x = 100;
let y = 100;
let speedX = 2.5;
let speedY = 3;
function setup() {
createCanvas(400, 300);
noStroke();
fill(255, 0, 150);
}
function draw() {
background(220);
ellipse(x, y, 50, 50);
x += speedX;
y += speedY;
if (x > width - 25 || x < 25) {
speedX *= -1;
}
if (y > height - 25 || y < 25) {
speedY *= -1;
}
}
// You can also use the instance-based approach if you prefer
// const mySketch = function(p) {
// let circleX = 50;
// let circleY = 50;
//
// p.setup = function() {
// p.createCanvas(200, 150);
// p.fill(0, 100, 200);
// p.noStroke();
// };
//
// p.draw = function() {
// p.background(240);
// p.circle(circleX, circleY, 30);
// circleX += 1;
// if (circleX > p.width + 15) {
// circleX = -15;
// }
// };
// };
//
// new p5(mySketch);
</script>
</body>
</html>
So now again my question, is the above described behavior due to a bug or me doing things the wrong way?
Thank you!