Skip to content

fix(resolve): don't use exports field for dir imports#20252

Closed
sapphi-red wants to merge 1 commit intovitejs:mainfrom
sapphi-red:fix/resolve-dont-use-exports-field-for-dir-imports
Closed

fix(resolve): don't use exports field for dir imports#20252
sapphi-red wants to merge 1 commit intovitejs:mainfrom
sapphi-red:fix/resolve-dont-use-exports-field-for-dir-imports

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Jun 20, 2025

Description

For require('./dir'), Node.js does not use the exports field of dir/package.json.
(Spec: LOAD_AS_DIRECTORY(X) step 1.b)
But Vite currently uses the exports field in that case.

This PR aligns the behavior to Node.js. This also aligns with oxc-resolver's behavior.

Note that this PR will break this line in nuxt.
https://github.com/nuxt/nuxt/blob/a7d21ece19e69703aac5fbb1f7bf53f0dfc5751f/test/setup-env.ts#L3

@sapphi-red sapphi-red added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Jun 20, 2025
@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 20, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20252

commit: 4067225

@vite-ecosystem-ci
Copy link

@sapphi-red
Copy link
Member Author

@sapphi-red sapphi-red marked this pull request as draft June 26, 2025 01:38
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Jun 26, 2025
closes #571

This is not part of the spec but some vite projects rely on this behavior.
See
* vitejs/vite#20252
* nodejs/node#58827
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Jun 26, 2025
closes #571

This is not part of the spec but some vite projects rely on this behavior.
See
* vitejs/vite#20252
* nodejs/node#58827
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Jun 26, 2025
closes #571

This is not part of the spec but some vite projects rely on this behavior.
See
* vitejs/vite#20252
* nodejs/node#58827
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Jun 26, 2025
)

closes #571

This is not part of the spec but some vite projects rely on this
behavior.

Opt-in by `allowPackageExportsInDirectoryResolve: true`.

See
* vitejs/vite#20252
* nodejs/node#58827
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Jun 26, 2025
For vitejs/vite#20252

---------

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
@sapphi-red
Copy link
Member Author

The behavior can now be aligned on native plugin side.

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

Labels

p2-edge-case Bug, but has workaround or limited in scope (priority) trigger: preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant