Skip to content

Failed to load resource #23949

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

Open
podsvirov opened this issue Mar 18, 2025 · 5 comments
Open

Failed to load resource #23949

podsvirov opened this issue Mar 18, 2025 · 5 comments

Comments

@podsvirov
Copy link
Contributor

podsvirov commented Mar 18, 2025

Please include the following in your bug report:

Version of emscripten/emsdk:

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.5-git (53b38d0c6f9fce1b62c55a8012bc6477f7a42711)
clang version 21.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:/msys64/clang64/opt/emscripten-llvm/bin

Failing command line in full:

I was just customize Using files example
from Emscripten Tutorial page:

$ mkdir -p out/static
$ ./emcc test/hello_world_file.cpp -o out/static/hello.mjs --preload-file test/hello_world_file.txt
$ cat > out/index.html << EOL
<!DOCTYPE html>
<html>
<body>
        <script type="module">
                import initModule from './static/hello.mjs';
                initModule({
                        print: (text) => { document.body.innerText += text + '\n'; }
                });
        </script>
</body>
</html>
EOL
$ ./emrun out/index.html

Failure from browser console:

Failed to load resource: the server responded with a status of 404 (File not found: <current path>/out/hello.data)

Module hello.mjs search hello.data in out subdirectory (local webserver root). But hello.mjs sould search hello.data from ./static/ supdirecotry where hello.mjs hosted himself.

Then we mode hello.data to out from out/static and run again:

$ mv out/static/hello.data out/
$ ./emrun out/index.html

And see text in browser:

==
This data has been read from a file.
The file is readable as if it were at the same location in the filesystem, including directories, as in the local filesystem where you compiled the source.
==
@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

Indeed it looks like we should loading the preload data file relative to the .mjs files by default.

BTW, have you considered switching from --preload-file to --embind-file the later will embed the data directly into the wasm file saving download size and memory copying.

@podsvirov
Copy link
Contributor Author

Sounds good, but where I can read about the --embind-file option more?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

@podsvirov
Copy link
Contributor Author

@podsvirov
Copy link
Contributor Author

BTW, have you considered switching from --preload-file to --embind-file the later will embed the data directly into the wasm file saving download size and memory copying.

Oh, looks like we was speak about the --embed-file option! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants