3 ms·
Doesn't work in a browser [1]: > file: URLs are supported by many non-browser runtimes such as Node, since scripts there already have file: URLs, but they are
by codedokode 2y ago
Doesn't work in a browser [1]:
> file: URLs are supported by many non-browser runtimes such as Node, since scripts there already have file: URLs, but they are not supported by browsers due to security reasons.
If you open HTML file directly in a browser, it cannot import ES modules from a filesystem. It can import legacy scripts, but they, as I understand, cannot import anything at all.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- tpm 2y agoYou don't need file:// module URLs when you say open a index.html from your local drive through file://C:/index.html but then in that index.html you have a 'script type="module" src="src/index.js"' and from there you go through usual relative paths without protocol. This works in Firefox, I have one project open like that right now. Chrome blocks that because of their CORS policy, but that's another issue, can be mitigated by some commandline options (--allow-file-access-from-files --cors-exempt-headers "*")
- matt_kantor 2y ago> Chrome blocks that because of their CORS policy Firefox has the same behavior (I just tested using Firefox 136 on macOS). The error message says "CORS request not HTTP"[0]. You might have disabled `security.fileuri.strict_origin_policy` in about:config? [0]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS/Errors/CORSRequestNotHttp https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/COR...
- tpm 2y agoYeah, happened long ago so I didn't remember it. Still for dev env I think it's a reasonable tradeoff.