You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebAssembly.instantiate(): illegal flag value 90 @+642213 when -sSINGLE_FILE=1 in release build #27156
when using -sSINGLE_FILE=1 in Release i get this Error in the browser console dev tool
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): illegal flag value 90 @+642213
index.html:1 Uncaught (in promise) TypeError: A.startsWith is not a function
at isFileURI (index.html:1:4330)
at instantiateArrayBuffer (index.html:1:9272375)
at async createWasm (index.html:1:9273430)
index.html:1:4330 is var isFileURI = A => A.startsWith("file://");
Does this happen on latest main? (emsdk install tot)
it happens in release build (Only) when SINGLE_FILE=1.
not in debug build even if SINGLE_FILE=1 or 0
I don't know exactly. I'm using GitHub CI to automatically fetch the latest Emscripten SDK with the GitHub Action emscripten-core/setup-emsdk@v16.
My project is public, and I think it's a fairly simple CMake build for the web. All of my dependencies are either vendored into the repository or included as Git submodules, so the issue should be reproducible
I think the problem is likely the illegal flag value 90 @+642213. I.e. maybe the wasm file is actually invalid in some way.
yes not file maybe when embeded to the js or html not encoded correctly some edge case maybe and this with happens only when some combination of flags with SINGLE_FILE maybe flags i use
shared flags (debug/release)
Out of interest, what are your actual requirements? Do you need to JS to be embeded into the html or would it be enough to embed the wasm into the JS?
I really liked using a single-file WASM build embedded into JS but I set set_target_properties(${target} PROPERTIES SUFFIX ".html") so it gets embedded into HTML via Emscripten. This way, no server is required. I’m also embedding all of my resources just to iterate faster on my project.
Do you find that these embedding actually make things faster?
In any case it sounds like you have a workaround for now in the form of -sSINGLE_FILE_BINARY_ENCODE=0. Its still a mystery exactly why its not working your case, and its good we kept that options for around for cases like this.
One more thing: Are you attached to having Emscripten generate your html? For most users we just recommend generating the .js and then having the .html maintained by hand.
Do you find that these embedding actually make things faster?
In any case it sounds like you have a workaround for now in the form of -sSINGLE_FILE_BINARY_ENCODE=0. Its still a mystery exactly why its not working your case, and its good we kept that options for around for cases like this.
not about the speed it just makes my cmake pack system simple i was dowing the .js then by hand including it but i found out i could use --shell-file and set CMAKE_PREFIX to "html" only need to pack .html alone. if this bug not bad ok you can close this issue but maybe its far more than this and affecting other thing ?
One more thing: Are you attached to having Emscripten generate your html? For most users we just recommend generating the .js and then having the .html maintained by hand.
yeh both options are good for me i dont care if i or cmake generates the html but the --shell-file whats its purpose ?
As a starting point: It allows emscripten to generate a starting point for an html file so folks can see their program running right away. Once such users has a taken a look at the generated HTML they would normally just create their own site and embed the JS directly.
A way to have single HTML file for for may targets: For example if you are building a higher level SDK on top of emscripten you might have not want to create your own html-generated and instead just use s simple html template that you pass to --shell-file. This not a very common case though, since more users have a fixed/static number of targets which don't share html-embedding needs.
For the first case we don't even need the --shell-file option, we just need single template embedded in emscripten.
The second case is really very rare I think. Maybe it could used to unit testing of demo generation where each program has the came html-embedding needs? But its also very trivial to write a html-generated-based-on-template outside of emscripten. For this reason I'd really like to remove --shell-file one day. html-templating is not a the core competency of emscripten, we should expect higher level tools to do that.
if this bug not bad ok you can close this issue but maybe its far more than this and affecting other thing ?
Sorry, I'm not saying this bug is not bad, or should not be fixed. I'm mostly suggesting that you use the workaround until somebody has time to figure out the root cause. I don't have time for look into myself right now but maybe somebody will. I'll mark the bug as Help Wanted.
I believe I might be able to shed some light onto this issue:
TL;DR html-minifier-terser postprocesses the string which corrupts the binary.
Longer story: html-minifier-terser has this --ignore-custom-fragments flag, which has a special handling for PHP/ASP/etc. preprocessors which happens to match by pure chance with this WASM binary and results in extra whitespace characters to be added.
Passing --ignore-custom-fragments '[]' in
err(`warning: Loading from a file URI (${binaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
}
the isFileUri function is called with a Uint8Array not a regular string in the SINGLE_FILE_BINARY_ENCODE case.
Activity
kripken commentedon Jun 22, 2026
This could be a bug in SINGLE_FILE.
main? (emsdk install tot)sbc100 commentedon Jun 22, 2026
I think the problem is likely the
illegal flag value 90 @+642213. I.e. maybe the wasm file is actually invalid in some way.sefyan0hack commentedon Jun 22, 2026
not in debug build even if SINGLE_FILE=1 or 0
My project is public, and I think it's a fairly simple CMake build for the web. All of my dependencies are either vendored into the repository or included as Git submodules, so the issue should be reproducible
sefyan0hack commentedon Jun 22, 2026
yes not file maybe when embeded to the js or html not encoded correctly some edge case maybe and this with happens only when some combination of flags with SINGLE_FILE maybe flags i use
shared flags (debug/release)
(debug)
sbc100 commentedon Jun 22, 2026
The embedded wasm file does look invalid for some reason.
I'm attached a copy of it:
index.wasm.zip
Wabt seems to agree about the issue:
Binaryen sees a different issue:
I guess this could be some kind of issue with out binary embedding?
Is your
index.htmlfile encoded as UTF-8? Does-sSINGLE_FILE_BINARY_ENCODE=0fix the issue? @juj any ideas?sefyan0hack commentedon Jun 22, 2026
yes
-sSINGLE_FILE_BINARY_ENCODE=0fixes the broblem for mesbc100 commentedon Jun 22, 2026
I assume this must be something about the html file encoding is setup. See the docs for SINGLE_FILE_BINARY_ENCODE: https://emscripten.org/docs/tools_reference/settings_reference.html#single-file-binary-encode.
I wonder if we can do better at detecting and reporting this kind of problem? @juj?
sefyan0hack commentedon Jun 22, 2026
i have
<meta charset="utf-8">in custom shel. index.hmtlsbc100 commentedon Jun 22, 2026
Out of interest, what are your actual requirements? Do you need to JS to be embeded into the html or would it be enough to embed the wasm into the JS?
sefyan0hack commentedon Jun 23, 2026
I really liked using a single-file WASM build embedded into JS but I set
set_target_properties(${target} PROPERTIES SUFFIX ".html")so it gets embedded into HTML via Emscripten. This way, no server is required. I’m also embedding all of my resources just to iterate faster on my project.sbc100 commentedon Jun 23, 2026
Do you find that these embedding actually make things faster?
In any case it sounds like you have a workaround for now in the form of
-sSINGLE_FILE_BINARY_ENCODE=0. Its still a mystery exactly why its not working your case, and its good we kept that options for around for cases like this.sbc100 commentedon Jun 23, 2026
One more thing: Are you attached to having Emscripten generate your html? For most users we just recommend generating the
.jsand then having the.htmlmaintained by hand.sefyan0hack commentedon Jun 23, 2026
not about the speed it just makes my cmake pack system simple i was dowing the .js then by hand including it but i found out i could use
--shell-fileand set CMAKE_PREFIX to "html" only need to pack .html alone. if this bug not bad ok you can close this issue but maybe its far more than this and affecting other thing ?sefyan0hack commentedon Jun 23, 2026
yeh both options are good for me i dont care if i or cmake generates the html but the
--shell-filewhats its purpose ?sbc100 commentedon Jun 23, 2026
--shell-fileI think kind of serves 2 purposes:--shell-file. This not a very common case though, since more users have a fixed/static number of targets which don't share html-embedding needs.For the first case we don't even need the
--shell-fileoption, we just need single template embedded in emscripten.The second case is really very rare I think. Maybe it could used to unit testing of demo generation where each program has the came html-embedding needs? But its also very trivial to write a html-generated-based-on-template outside of emscripten. For this reason I'd really like to remove
--shell-fileone day. html-templating is not a the core competency of emscripten, we should expect higher level tools to do that.sbc100 commentedon Jun 23, 2026
Sorry, I'm not saying this bug is not bad, or should not be fixed. I'm mostly suggesting that you use the workaround until somebody has time to figure out the root cause. I don't have time for look into myself right now but maybe somebody will. I'll mark the bug as Help Wanted.
RobinTF commentedon Aug 9, 2026
I believe I might be able to shed some light onto this issue:
TL;DR
html-minifier-terserpostprocesses the string which corrupts the binary.Longer story:
html-minifier-terserhas this--ignore-custom-fragmentsflag, which has a special handling for PHP/ASP/etc. preprocessors which happens to match by pure chance with this WASM binary and results in extra whitespace characters to be added.Passing
--ignore-custom-fragments '[]'inemscripten/tools/link.py
Lines 2617 to 2656 in b1fc37f
The secondary issue with
index.html:1 Uncaught (in promise) TypeError: A.startsWith is not a functionhappens because in the error handling caseemscripten/src/preamble.js
Lines 615 to 617 in b1fc37f
the
isFileUrifunction is called with aUint8Arraynot a regular string in theSINGLE_FILE_BINARY_ENCODEcase.[link] Prevent HTML minification from corrupting embedded WASM data
sbc100 commentedon Aug 10, 2026
Thanks for investigating. I uploaded #27509 for the terser issue. I'll followup with a fix for the call to isFileUrl too
[preamble] Do not check isFileURI in SINGLE_FILE mode
Prevent HTML minification from corrupting embedded WASM data (emscrip…
[preamble] Do not check isFileURI in SINGLE_FILE mode
Do not check `isFileURI` in `SINGLE_FILE` mode (#27521)