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

TypeError: react is not a function when importing via commonjs #14

Closed
benatshippabo opened this issue Dec 9, 2022 · 3 comments
Closed

Comments

@benatshippabo
Copy link

When using commonjs imports

const react = require('@vitejs/plugin-react-swc');

We get TypeError: react is not a function. It works with esm imports, but I thought this was worth bringing up.

Example reproduction:

https://stackblitz.com/edit/vitejs-vite-tcrxby?file=vite.config.js

@ArnaudBarre
Copy link
Member

ArnaudBarre commented Dec 9, 2022

There is not SWC bindings available for Stackblitz yet, so with ESM it fails just after. That's strange though, there is probably an issue with default export. Thanks for reporting!

@ArnaudBarre
Copy link
Member

So yeah basically this a classic interop issue, which is why we should move away from default export (or cjs, but one is simpler than the other).

I can patch esbuild output for the cjs output, but before doing that I want to know if it will be possible to support this directly in esbuild: evanw/esbuild#2733

In the meantime you can change your export to require('@vitejs/plugin-react-swc').default

@ArnaudBarre
Copy link
Member

This is will be fixed in the next path in few days

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