11 ms·
I am surprised they still use outdated syntax when there is a standard for modules. Also, it is much better when you specify full path to the file and do not h
by codedokode 2y ago
I am surprised they still use outdated syntax when there is a standard for modules. Also, it is much better when you specify full path to the file and do not have to remember the resolving rules.
Also, last time I tried to use ESM in a browser with Vue and unpkg without builders and web server, it didn't work (probably because one cannot import modules from a local folder). I wish support for ESM and localhost was improved also. I don't want to use a webserver or a bundler because it is easier without them so I switched to legacy scripts without modules.
- tpm 2y ago> one cannot import modules from a local folder Pretty sure this works and it is indeed possible to use ES modules without builders and a webserver, I recently rewrote a Node app this way (with Claude's help even because I'm a ES noob). No idea about Vue and unpkg though, there could be an issue with that. edit: eh you mean like "import 'file://module.js'", but I don't understand why would you need that when you can use "import './module.js'"
- codedokode 2y agoDoesn'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.
- WorldMaker 2y agoWhile you can't use it without a webserver, today that webserver can be a one-liner like `npx http-server` or `python -m http.server` at least.