emscripten-core / emscripten-core/emscripten

FS_createPreloadedFile not supported in MEMFS under node.js, but could easily be

Open
#16,742 3 comments 0 reactions 0 assignees View on GitHub
good first bug help wanted
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I have code that runs in the browser using lazily loaded files, and I would very much like to be able to test it on the command-line using node.js without having to recompile it. As noted in https://github.com/emscripten-core/emscripten/issues/16740, lazy loading is broken under node.js because it corrupts binary files. So the alternative is to pre-load these files in a preRun() callback.

Unfortunately this doesn't work either, because createPreloadedFile() calls Browser.handledByPreloadPlugin(), but since this is node.js, there is no Browser:

https://github.com/emscripten-core/emscripten/blob/c38e6c8cfba28980aea8f895c71b376e8a5155d5/src/library_fs.js#L1864

Well, that's fine, this is JavaScript after all, I can just make a dummy Browser object in my test code, and now it works:
```js
Browser = {
handledByPreloadPlugin() {
return false;
}
};

```

But really I shouldn't have to do this :) Am I missing something in the documentation, is there a better way to do this (yes, I know that I can just use NODEFS or NODERAWFS, but as mentioned above, I don't want to recompile just to run a test).

My emscripten version:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.8 (3ff7eff373d31d8c0179895165462019221f192e)
clang version 15.0.0 (https://github.com/llvm/llvm-project 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.