New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ports/webassembly: import of a preloaded Emscripten FS fails on Node #14358
Comments
Thanks for the report, I can reproduce the issues. I think this is a bug in Emscripten: it's not possible to use It looks like this may have been fixed very recently in Emscripten by: emscripten-core/emscripten#21721 (see previous emscripten-core/emscripten#18317 which shows the same error as reported here). |
Thanks for the feedback! I updated emscripten to 3.1.59 and using the latest micropython master. The above error disappears, but now I get the following:
It looks like it misses the (I preloaded a folder |
I'm sorry I have misread how to use the This argument can only be used if the resulting Using the call like that (in the makefile): and using the repl afterwards:
correctly imports me the given files. So that's great! Since that's a functionality that may be quite often used, perhaps could be added as option to the makefile call (like e.g. |
Yes, that sounds reasonable. Although a better solution for the end user would be a way to do it that doesn't require compiling the const { loadMicroPython } = await import(`${base}/micropython.mjs`);
const mp = await loadMicroPython({ url: `${base}/micropython.wasm` });
mp.FS.mkdir("/lib");
mp.FS.writeFile("/lib/cloud.py", await (await fetch("cloud.py")).text());
mp.FS.writeFile("/lib/utils.py", await (await fetch("utils.py")).text()); That would download each py file independently, so not be efficient with HTTP(S) traffic. But you could bundle all your files into a big JSON and fetch that, then iterate it and create the filesystem. (Actually, pyscript provides a nice interface to do this kind of thing, if you want to use that.) |
Checks
I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.
I've searched for existing issues matching this bug, and didn't find any.
Port, board and/or hardware
webassembly
MicroPython version
MicroPython v1.23.0-preview.324.g6634fea23.dirty on 2024-04-22; JS with Emscripten
(I've added more modules to the manifest)
Reproduction
node build-pyscript/micropython.mjs
-> OKso far so good - however... I want to "freeze" existing micropython files in an emscripten FS. For this I'm using the
--preload-file
argument in the makefile like this:$(Q)emcc $(LDFLAGS) -o $@ $(OBJ) $(JSFLAGS) --preload-file <directory_with_python_files>
this works as expected in the browser and I can successfully import it via
mp.pyimport(xxxx)
But I can't run the node repl with that
micropython.mjs
anymore. When trying to start the REPL I'm getting the following error:Expected behaviour
When building with
--preload-file
I'd expect that the REPL still starts and I can import the preloaded filesObserved behaviour
The above error appears (no REPL)
Additional Information
No, I've provided everything above.
The text was updated successfully, but these errors were encountered: