Skip to content

fix: resolve import exports for unknown Rspack dependencies - #353

Merged
dgaponov merged 2 commits into
mainfrom
fix/rspack-conditional-exports
Sep 8, 2026
Merged

dgaponov merged 2 commits into
mainfrom
fix/rspack-conditional-exports

Conversation

@nikita-jpg

@nikita-jpg nikita-jpg commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What

  • Add the import condition to Rspack resolution for dependencies classified as unknown.
  • Keep the existing require and module conditions.
  • Leave Webpack resolution unchanged.

Why

A JavaScript package can contain ESM imports while omitting type: module. Rspack may classify a nested dependency from such a package as unknown. When that dependency targets a public package subpath with separate import and require exports, the ESM branch is not considered and resolution can fail.

Scoping the additional condition to byDependency.unknown fixes this case without changing resolution conditions globally.

Reproduction example

@gravity-ui/chartkit@8.1.0 is an affected real-world package. Its Yagr plugin imports the public @gravity-ui/yagr/react subpath, with @gravity-ui/yagr@5.2.0 selected in the dependency graph.

An application built with Rspack can fail while bundling this dependency graph:

Package subpath './dist/react' is not defined by "exports" in @gravity-ui/yagr/package.json

With the import condition enabled for unknown dependencies, Rspack selects Yagr's public ESM export and the same dependency graph builds successfully.

Testing

  • pnpm test --runInBand
  • pnpm typecheck
  • pnpm lint
  • pnpm build
  • pnpm --filter "@examples/*" build

@dgaponov
dgaponov merged commit f1550e9 into main Sep 8, 2026
3 checks passed
@dgaponov
dgaponov deleted the fix/rspack-conditional-exports branch September 8, 2026 07:55
@gravity-ui gravity-ui Bot mentioned this pull request Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants