Hacker News new | ask | show | jobs
by geenat 1090 days ago
The problem with Javascript modules = Everyone will be forced to run a full web server to do anything (to handle CORS restrictions).

We all lose the ability to simply have a local index.html file, and have it Just Work (TM):

  <script src="script.js"></script>
This ability is amazing for demos, fast iteration, onboarding new devs and developing without a ton of layers of js ecosystem machinery.

Deno doesn't care about retaining this level of developer experience because Deno is marketing its own runtime / build step / ecosystem.

3 comments

If you are same origin, you do not require CORS to use type=module. Also type=module works on HTML pages served from file:// (file:///.../index.html).
I just tried this and got "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/**.js. (Reason: CORS request not http)" in firefox
It is not possible to do same origin from a file system. Everything served from a file system is considered to be different origins. This drives me bonkers.
Because browser makers only have respect for the bourgeoisie and clear contempt for the proletariat.
Is CommonJS even a thing for javascript running in web browsers? Moving from CommonJS to modules shouldn't affect any running in a browser.
Sure it is. I've used it via require.js. There were other ways too.
Using require.js is your choice. CommonJS often isn't a choice.
> <script src="/js/anything.js" ></script>

Shouldn't that be a relative path for it to actually work as you intend?

It just needs to be browser resolvable, assuming this element is meant to run in a browser. So absolute paths do work. For libraries, you may want to use import maps or absolute urls (similar to Deno). There's also esm.sh and jspm.org for modules that are able to be relatively easily converted.

I think it may be necessary/prudent to get some level of JSX support into browsers, much like the ts as comments efforts. Not sure how that will/would land. I was a pretty big fan of E4X, and had a prototype similar to React about a decade before it. In the end, who knows.