Incorrect resolving priority extensions (e.g. .web.tsx vs .tsx) in node_modules during optimizeDeps (original) (raw)

Describe the bug

There seems to be an issue with optimizeDeps.esbuildOptions.resolveExtensions when running Vite in dev mode during optimizing deps from node_modules.

I recently had to update my plugin (vite-plugin-react-native-web) with a hotfix. In react-native on web different files are imported using the .web.tsx file. The build tool has to prioritize .web.tsx above .tsx when searching the correct file to import in the file system. The optimizeDeps.esbuildOptions.resolveExtensions in previous versions worked perfectly for me. For files in my own ./src directory it still works fine, but when optimizing deps in node_modules the prioritized extensions seem to be ignored.

In my example project provided, you can test the bug by uncommenting lines 64-68 in rnw.ts (the hotfix). The package expo-image uses .web.tsx to import the correct file. Without this hotfix when running vite in dev mode it will fail.

When building in Vite, the files are always imported correctly.

Reproduction

https://github.com/Bram-dc/vite-react-native-web

Steps to reproduce

You can see in the chrome debugger that ExpoImage.tsx is incorrectly imported.

System Info

System: OS: Windows 11 10.0.22631 CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz Memory: 2.99 GB / 15.78 GB Binaries: Node: 22.8.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Chromium (127.0.2651.86) Internet Explorer: 11.0.22621.3527 npmPackages: @vitejs/plugin-react-swc: ^3.7.2 => 3.7.2 vite: ^6.0.11 => 6.0.11

Used Package Manager

npm

Logs

No response

Validations