netlify / edge-bundler

Intelligently prepare Netlify Edge Functions for deployment

Home Page:https://www.npmjs.com/package/@netlify/edge-bundler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: How to use JSX in Edge Functions with global React

charkour opened this issue · comments

Describe the bug

When setting the compilerOptions.jsxImportSource in our Deno configuration file to use JSX within a Netlify Edge Function without importing the JSX source (React) we get the following error: ReferenceError: React is not defined.

The Netlify Edge Function docs do have an example where React is imported so the React JSX is in the scope of the Edge Function; however, it does not specify that this is the only way.

Please let me know if this is expected or if it's an issue. For us, this is an issue because unused imports will be removed by our linter which means React will be removed even if it is required only for the JSX. Perhaps a workaround is to update our linter to ignore React.

Please view the reproduction here: https://github.com/charkour-labs/netlify-edge-function-gloabl-react

Thank you!

Configuration

 System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1
    Memory: 74.86 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.1.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 10.2.0 - /opt/homebrew/bin/npm
    pnpm: 8.12.1 - ~/Library/pnpm/pnpm
    bun: 1.0.6 - ~/.bun/bin/bun
    Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman

Netlify's build system doesn't take deno.json into account, so the behaviour you're seeing is expected. Changing your linter settings sounds like the best way forward.

Netlify's build system doesn't take deno.json into account, so the behaviour you're seeing is expected. Changing your linter settings sounds like the best way forward.

Sounds good, I'll work with my team to update our linter settings. Thanks for the help here! I'll close this issue.

Is supporting deno.json configuration on the product roadmap?

Is supporting deno.json configuration on the product roadmap?

Not currently, no.