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

Access to script at 'node:process' from origin 'http://localhost:8000' has been blocked by CORS #2480

Open
guy-borderless opened this issue May 30, 2024 · 1 comment

Comments

@guy-borderless
Copy link

guy-borderless commented May 30, 2024

repro-repo
The following island taken from headless-ui example page fails to hydrate on the client with the error:

Access to script at 'node:process' from origin 'http://localhost:8000' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

image
import is:

import {
  Listbox,
  ListboxButton,
  ListboxOption,
  ListboxOptions,
} from "https://esm.sh/@headlessui/[email protected]?external=react,react-dom,@types/react";

Island code

@lishaduck
Copy link

lishaduck commented May 30, 2024

I don't know the "right" way to fix it, but I know the issue, and from there a somewhat hacky solution :)
Combobox virtualization can't be tested right using Jest for some reason, so HeadlessUI's virtualization code is set inside an if (typeof process !== 'undefined' && process.env.JEST_WORKER_ID !== undefined) block. esm.sh then compiles that to include import __Process$ from "node:process"; because the modules is being requested by Deno, so it assumes that Deno's Node compatibility layer will be applied. To fix it, just add "node:process": "https://esm.sh/v135/node_process.js" to your import map, which re-adds esm.sh's own browser-based Node compatibility layer.

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

No branches or pull requests

3 participants