Skip to content

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

Open
eriestrisnadi wants to merge 1 commit intoianstormtaylor:mainfrom
eriestrisnadi:fix/umd-ext
Open

Fix UMD Build .cjs Extension Blocked Due to Incorrect MIME Type#1293
eriestrisnadi wants to merge 1 commit intoianstormtaylor:mainfrom
eriestrisnadi:fix/umd-ext

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