Skip to content

Module field breaking CommonJS resolution #7578

@SteveALee

Description

@SteveALee

Describe the bug

A function in a nested require is not correctly processed.

sodatea said on discord:

A small bug in Vite's resolution algorithm. There's a module field in callbag-from-event, while callbag-for-each only has main. https://unpkg.com/browse/callbag-from-event@1.3.0/package.json#L10 module has higher precedence in Vite than main. https://github.com/vitejs/vite/blob/a74bd7ba9947be193bccf636b8918bd1f59e89ae/packages/vite/src/node/plugins/resolve.ts#L778-L786

The fix is similar to #7438 that module or jsnext fields should be skipped when it's initiated by a require call.

Reproduction

See https://stackblitz.com/edit/vitejs-vite-wthjcb?file=main.js

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions