-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Incorrect resolving priority extensions (e.g. .web.tsx vs .tsx) in node_modules during optimizeDeps #19291
Comments
Can you provide more details on which version of which package was working? |
I think I reproduced the issue with only esbuild https://stackblitz.com/edit/github-ktr747mh?file=repro.mjs. It looks like esbuild picks up FYI, workaround seems to be to put all resolveExtensions: [
// ⚠️ this doesn't work even though .tsx is after .web.tsx
'.web.mjs',
'.mjs',
'.web.js',
'.js',
'.web.mts',
'.mts',
'.web.ts',
'.ts',
'.web.jsx',
'.jsx',
'.web.tsx',
'.tsx',
'.json',
// ⚠️ this works
// '.web.mjs',
// '.web.js',
// '.web.mts',
// '.web.ts',
// '.web.jsx',
// '.web.tsx',
// '.mjs',
// '.js',
// '.mts',
// '.ts',
// '.jsx',
// '.tsx',
// '.json',
], |
Yes indeed, very weird that the .web needs to come first above all. I will create a bugreport for esbuild is the problem lies there. If the problem lies with esbuild, then why does it work fine after |
Nevermind, vite uses rollup then. |
Indeed the issue lies with esbuild: Bram-dc/vite-react-native-web@748a3f5. I will create a bug report there. |
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
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: