vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.81k stars 6k forks source link

Does Preact support Preact Compat? #1466

Closed nahtnam closed 3 years ago

nahtnam commented 3 years ago

Is your feature request related to a problem? Please describe. I'm trying to use React components with the preact-ts example but I'm not sure how to do it

Describe the solution you'd like A way to set up preact/compat to use react components

Describe alternatives you've considered I created a repo with the preact-ts preset, installed react, react-dom and @material-ui/core and its types and changed the tsconfig.json jsx option to preserve. Then I put a <Button on the homepage and got this error: Uncaught DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('[object Object]') is not a valid name. It didn't end up working so I'm not sure what to do.

Additional context N/A

Schniz commented 3 years ago

Have you tried keeping preact-ts as it is, and add the aliases?

 // vite.config.ts
 export default {
+  alias: {
+    react: 'preact/compat',
+    'react-dom': 'preact/compat'
+  }
 }

It is working on my example repo when I use @tabler/icons

yyx990803 commented 3 years ago

You need to install and alias to preact/compat like @Schniz showed.

nahtnam commented 3 years ago

Thanks @Schniz @yyx990803! This is a much better developer experience than preact-cli!