Skip to content

resolveExtensions not honoring .web.tsx when listed after .tsx for node_modules dependencies #4053

Closed
@Bram-dc

Description

I originally reported this issue to Vite, but the problem seems to originate in esbuild. (original issue)

When setting resolveExtensions to prioritize .web.tsx after .tsx, esbuild still picks up .tsx variants first in node_modules, even though it behaves correctly in local src code. Placing all .web entries before the non-web ones works around the issue, but it seems resolveExtensions is ignoring the intended ordering for packages in node_modules. It does work fine in files in the ./src directory for example.

Expected Behavior
Listing .web.tsx after .tsx in resolveExtensions should correctly pick up the .web.tsx variant for files in node_modules, just like it does for local src code.

Observed Behavior
When .web.tsx is listed after .tsx in resolveExtensions, esbuild still resolves to the .tsx file for dependencies in node_modules, rather than the .web.tsx variant.

Reproduction
Here is a minimal script demonstrating the behavior (see commented sections for the workaround). It uses expo-image from node_modules to illustrate the resolution bug. The github example has been narrowed down to exclude vite and uses esbuild only. https://github.com/Bram-dc/vite-react-native-web

You can switch around the commented resolveExtensions and also try the hotfix (lines 65-69)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions