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

Fix UMD Build .cjs Extension Blocked Due to Incorrect MIME Type #1293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eriestrisnadi
Copy link

Overview

Some browsers enforce strict Content Security Policy (CSP) or Cross-Origin Read Blocking (CORB) rules that check the MIME type of scripts. If the MIME type returned in the response headers doesn’t match the expected type for execution, the browser will block the script.

Example: JSDelivr

For instance, if you use the following snippet:

<script src="https://cdn.jsdelivr.net/npm/superstruct"></script>

JSDelivr will serve the script with a MIME type of application/node, which causes the browser to block it:

Image

Example: Unpkg

For instance, if you use the following snippet:

<script src="https://unpkg.com/superstruct"></script>

Unpkg will serve the script with a MIME type of text/plain, which will also result in the script being blocked:

Image

Suggested Fix

To resolve this issue, we recommend using the .js extension instead of .cjs. Changing the extension to .js when bundling will ensure proper execution of the script.

This change will help avoid MIME type mismatches and prevent browsers from blocking the script.

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

Successfully merging this pull request may close these issues.

1 participant