5

If I compile my C++ code with emcc without -s MODULARIZE=1 -s 'EXPORT_NAME="createMyModule"', I can load my WebAssembly and access the File System API like this:

HTML:

<script type="text/javascript">
  var Module = {
    onRuntimeInitialized: function() {
      console.log('Module loaded!');
      if (FS.mkdir) {
        console.log('File System API available!');
      }
    }
  };
</script>
<script type="text/javascript" src="myWebAssemblyModule.js"></script>
<script type="module" src="my.js"></script>

Log:

Module loaded!
File System API available!

But if I add -s MODULARIZE=1 -s 'EXPORT_NAME="createMyModule"' as compiler options, and try to access the File System API based on a Promise, it doesn't work:

HTML:

<script type="text/javascript" src="myWebAssemblyModule.js"></script>
<script type="module" src="my.js"></script>

my.js:

createMyModule().then(MyModule => {
  console.log('Module loaded!');
  if (MyModule.FS.mkdir) {
    console.log('File System API available!');
  }
});

Log:

Module loaded!

So how can I access the File System API with the "MODULARIZED/Promise based" approach?

MyModule.FS is accessible btw., but not MyModule.FS.mkdir.

1 Answer 1

3

To make FS available in a modularized build, you have to export it explicitly:

emcc ... -s 'EXPORTED_RUNTIME_METHODS=["FS"]'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.