Skip to content

Aliasing React to Preact in Deno #4247

@adamzerner

Description

@adamzerner

There is a section on the Getting Started page called "Aliasing React to Preact". There is no example for how to do this in a Deno project. So 1) I'd like to ask how to do so in a Deno project, and 2) I'd like to propose that a Deno example be added to "Aliasing React to Preact".

Context: I am using Fresh, am trying to use Sandpack, and get the following error when I do. This error is because Sandpack uses React's useState and Fresh uses Preact. I think (but am unsure) that what I need to do to resolve this is alias React to preact/compat.

TypeError: Cannot read properties of null (reading 'useState')
    at Module.n.useState (https://esm.sh/stable/react@18.2.0/denonext/react.mjs:2:6891)
    at Object.Za (https://esm.sh/v135/@codesandbox/sandpack-react@2.8.0/denonext/sandpack-react.mjs:690:7478)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:3237)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:2543)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:5050)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:3802)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:2543)
    at m (https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:5050)

As a guess, I tried doing:

"react": "npm:preact/compat",
"react-dom": "npm:preact/compat",
"react/jsx-runtime": "npm:preact/jsx-runtime"

in imports in deno.json but it didn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions