How to use 'import' in P5?

In P5.js, how to use ES6’s import in top of sketch.js?

1 Like

Do you mean JS’ native ECMAScript Modules (ESM) by the way: :sunglasses:

Unfortunately, p5js library isn’t yet natively “importable” by JS newest import keyword, nor by its corresponding builtin import() function: :crying_cat_face:

Actually, even very famous libraries/frameworks like React aren’t compatible w/ it yet w/o relying on some other 3rd-party solutions: :flushed:

However, even though p5js isn’t itself compatible w/ this latest JS feature, we can still split our own sketches as ES modules, like I did once for my sketch “Ball-in-the-Chamber”: :heavy_division_sign:

1 Like