You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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. 😞
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
@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.
Activity
Potherca commentedon May 10, 2023
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. 😞
Potherca commentedon May 10, 2023
If I understand correctly (based on #65), the content-type comes from the
mimepackage?It is currently pinned at 2.4.*
https://github.com/mjackson/unpkg/blob/af8c8db00fdacd77961ab2a8c3edb45a27d3a6a3/package.json#L35
The
cjswas added in v2.4.5 asapplication/node, so it should work.Not sure why it doesn't. What am I missing?
Potherca commentedon May 10, 2023
As a workaround, I am using the
?moduleparameter to get the correct content-type.benmccann commentedon Jun 8, 2023
Looks like the lockfile needs to be updated:
https://github.com/mjackson/unpkg/blob/af8c8db00fdacd77961ab2a8c3edb45a27d3a6a3/yarn.lock#L4620
maximedupre commentedon Aug 7, 2023
#364 sounds like an easy merge 🥹
Can we get this done?
MedievalMatt commentedon Feb 17, 2024
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."
benmccann commentedon Feb 17, 2024
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/nodethe same asapplication/javascript. The PR should still be merged so that.cjsfiles will be served according to the spec, but I'm not so sure it's actually going to help anyonebrianlagunas commentedon Jun 24, 2024
This is still an issue. As you can see with this packages: https://unpkg.com/browse/@revealbi/ui@0.2.0/
The
.cjsfiles are marked astext/plainand will load not as javascript using a script tagSwivelgames commentedon Jul 25, 2024
@brianlagunas Unfortunately, it looks like
unpkghasn'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.
Swivelgames commentedon Jul 25, 2024
@Potherca described a workaround in the other issue (as well as above) for the time-being. Appending the
.cjsURL with?moduleapparently forces the correct MIME type.mjackson commentedon Mar 19, 2025
I changed this in b75b59f.
.cjsfiles are now served astext/javascript.