`*.cjs` extension files served as text/plain
Swivelgames opened this issue · 10 comments
Modern Node.js modules can be served as ESMs or CommonJS modules. These are differentiated either by their package.json
, or by the extension of the file. It appears that unpkg
properly serves .mjs
files, but seems to treat *.cjs
files as plaintext incorrectly.
Instead of text/plain
, the content-type
of .cjs
files should be application/javascript
.
Node's documentation can serve as reference for the honoring of these files: https://nodejs.org/api/modules.html#enabling
Running into this as well. Looks like this issue has been reported in 2020 in #268.
Would be nice to have as this basically makes UNPKG unusable for a large part of the JS ecosystem. 😞
As a workaround, I am using the ?module
parameter to get the correct content-type.
#364 sounds like an easy merge 🥹
Can we get this done?
This is still an issue as of February 2024. unpkg.com/three (direct link https://unpkg.com/three@0.161.0/build/three.cjs) throws up a nosniffer error and is being read as "text/plain."
The cjs was added in v2.4.5 as application/node, so it should work.
I was working off of this statement when I sent the PR, but am not sure it's accurate. I don't think Chrome will treat application/node
the same as application/javascript
. The PR should still be merged so that .cjs
files will be served according to the spec, but I'm not so sure it's actually going to help anyone
This is still an issue. As you can see with this packages: https://unpkg.com/browse/@revealbi/ui@0.2.0/
The .cjs
files are marked as text/plain
and will load not as javascript using a script tag
<script src="https://unpkg.com/@revealbi/ui@0.2.0/index.umd.cjs"></script>
@brianlagunas Unfortunately, it looks like unpkg
hasn't been touched for about 3 years. I'm starting to lose hope, unfortunately.
It doesn't look like the SPONSORS.md file has been updated for even longer suggesting that, despite its popularity, it might not have the funding necessary to continue to be maintained.
This is all purely speculation, of course, and I hope that the project is updated and maintained going forward!
#364 was opened about a year ago and it was approved a couple months later, but there's been no movement since.
@Potherca described a workaround in the other issue (as well as above) for the time-being. Appending the .cjs
URL with ?module
apparently forces the correct MIME type.