Description
Nature of issue?
- Existing feature enhancement
NOTE: I am not sure if this is technically an enhancement request or not. If it is not possible to import
other files into a sketch in the Web Editor, then this is an enhancement request. (Otherwise, I suppose it’s a…support request (?).)
Feature enhancement details:
I’m learning p5.js, and loving it so far. The web editor definitely makes it easier to jump in and play!
After modifying an existing example, the code got long enough for me to want to split it up into multiple files. However, I don’t want to pollute the global namespace (I actually started out by modifying the example to use P5 in instance mode), so I want to split the code up using JS modules.
But I keep getting the following error in the Web Editor:
Module name, './config.js' does not resolve to a valid URL.
But that file is in the same folder, so I don’t know why this is happening.
(I even tried renaming the file to use the .mjs
extension, but no luck.)
So…
How can I import
other files into a sketch on the Web Editor?
Activity
welcome commentedon Oct 2, 2021
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.
I-Omnibus commentedon Oct 9, 2021
Here's a workaround, although it seems that the solution is as simple as editor.p5.org getting the mime type right for JavaScript files:
GregStanton commentedon Jun 21, 2023
Hi all! I was looking into using modules with the web editor because I'm investigating different options for designing a p5.js add-on library. I made this minimal reproducible example to test out the behavior, and the resulting error message is similar to the one being discussed. I thought I would post the example here in case it's helpful.
backspaces commentedon Jul 13, 2024
So the question I have is: does the p5 web editor support import statements like:
import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js'
or do i have to use a dynamic import like this: