vite_plugin_deno_resolve icon indicating copy to clipboard operation
vite_plugin_deno_resolve copied to clipboard

Vite react plugin doesn't work as it can't find dependencies

Open itsdouges opened this issue 1 year ago • 5 comments

Two problems currently:

  1. Prebundling can't find the dependencies (react, react/jsx-runtime, react/jsx-dev-runtime) as it's currently hardcoded in Vite to use the node resolver. We can "work around this" by removing them from config.optimizeDeps.include during configResolved step
  2. After doing that there is... still problems. Same issue basically.
2:28:45 pm [vite] Internal server error: Failed to resolve import "react/jsx-dev-runtime" from "react/jsx-dev-runtime". Does the file exist?

🤔

Initial way forward: Don't use it. Next way forward: Fork? Future way forward: Contribute to the plugin to make it work with Deno?

itsdouges avatar Dec 24 '22 03:12 itsdouges

Prebundling can't find the dependencies (react, react/jsx-runtime, react/jsx-dev-runtime) as it's currently hardcoded in Vite to use the node resolver. We can "work around this" by removing them from config.optimizeDeps.include during configResolved step

How do you force prebundling @itsdouges? It seems the problem is that esbuild can't find this dependencies, which would be handled by providing a similar resolver to esbuild so it can search through Deno's cache.

bartlomieju avatar Dec 26 '22 16:12 bartlomieju

I was digging through the optimizer code and saw it instantiates the node resolve plugin there so I made the assumption that's what's happening 🤔

Im not sure if this is forcing prebundling but the includes array can take any package name, similar to dedupe.

itsdouges avatar Dec 26 '22 19:12 itsdouges

I was digging through the optimizer code and saw it instantiates the node resolve plugin there so I made the assumption that's what's happening 🤔

Im not sure if this is forcing prebundling but the includes array can take any package name, similar to dedupe.

Could you show me your configuration? I can't get it to work in any way...

bartlomieju avatar Dec 26 '22 20:12 bartlomieju

https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L394

This?

itsdouges avatar Dec 26 '22 20:12 itsdouges

Thanks, I took a stab at it and running into some very strange problems arising from my lack of knowledge on Vite internals. I'll try to get send some questions towards Vite maintainers to get more info what is expected from our side.

bartlomieju avatar Dec 26 '22 22:12 bartlomieju