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

Fail to load React 19 #163

Closed
zengfan1992 opened this issue Jan 23, 2025 · 1 comment
Closed

Fail to load React 19 #163

zengfan1992 opened this issue Jan 23, 2025 · 1 comment

Comments

@zengfan1992
Copy link

import React from "https://esm.sh/react@19.0.0"

It will load https://esm.sh/stable/react@19.0.0/denonext/react.mjs, but script include code 'import __Process$ from "node:process"'
It should load https://esm.sh/react@19.0.0/es2022/react.mjs, the script has no such problem.

Why https://esm.sh/react@19.0.0 redirect to https://esm.sh/stable/react@19.0.0/denonext/react.mjs?

PS: my solution

import esbuild from "https://deno.land/x/esbuild@v0.24.2/mod.js"
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@0.11.1"
const denoJson = await Deno.readTextFile("deno.json")
const imports = JSON.parse(denoJson).imports
const importMapURL = 'data:application/json,' + JSON.stringify({
    imports: Object.assign({
        "react": "https://esm.sh/react@19.0.0/es2022/react.mjs",
        "react-dom/client": "https://esm.sh/react-dom@19.0.0/es2022/client.mjs"
    }, imports)
})
if (Deno.args[0] === "dev") {
    const ctx = await esbuild.context({
        plugins: [...denoPlugins({ importMapURL })],
@unimonkiez
Copy link

For me this worked

// deno.json
{
  "imports": {
    "react": "npm:react@19.0.0"
  }
}
// src/react.d.ts
declare module "react" {
  // @deno-types="npm:@types/react@19.0.8"
  import React from "npm:react@19.0.0";
  export default React;
}

And then simply import

import React from "react";

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

2 participants