Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*.cjs extension files served as text/plain #355

Open
Swivelgames opened this issue Mar 15, 2023 · 10 comments
Open

*.cjs extension files served as text/plain #355

Swivelgames opened this issue Mar 15, 2023 · 10 comments

Comments

@Swivelgames
Copy link

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

@Potherca
Copy link

Potherca commented 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
Copy link

Potherca commented May 10, 2023

If I understand correctly (based on #65), the content-type comes from the mime package?

It is currently pinned at 2.4.*

"mime": "^2.4.0",

The cjs was added in v2.4.5 as application/node, so it should work.

Not sure why it doesn't. What am I missing?

@Potherca
Copy link

As a workaround, I am using the ?module parameter to get the correct content-type.

@benmccann
Copy link

The cjs was added in v2.4.5 as application/node, so it should work.
Not sure why it doesn't. What am I missing?

Looks like the lockfile needs to be updated:

unpkg/yarn.lock

Line 4620 in af8c8db

version "2.4.3"

@maximedupre
Copy link

#364 sounds like an easy merge 🥹

Can we get this done?

@MedievalMatt
Copy link

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
Copy link

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
Copy link

brianlagunas commented 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 .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>

@Swivelgames
Copy link
Author

@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.

@Swivelgames
Copy link
Author

Swivelgames commented Jul 25, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants