Skip to content

fix(react, aspect): drop the @teambit/webpack dependency, source types elsewhere - #10620

Merged
GiladShoham merged 1 commit into
masterfrom
fix/react-env-drop-teambit-webpack-dep
Aug 14, 2026
Merged

GiladShoham merged 1 commit into
masterfrom
fix/react-env-drop-teambit-webpack-dep

Conversation

@GiladShoham

Copy link
Copy Markdown
Member

Summary

react.env, react.main.runtime, and the app-build files only ever needed WebpackConfigTransformer / WebpackConfigMutator / Configuration types from @teambit/webpack (the old core-aspect package). Same for aspect.env. Those type-only imports still made bit's dependency resolver add @teambit/webpack as a real runtime dependency of the published @teambit/react/@teambit/aspect packages.

@teambit/webpack carries its own exact-pinned [email protected] + webpack-assets-manifest, separate from the webpack-bundler/webpack-dev-server packages react/aspect actually bundle with (PR #10610). pnpm resolves these as two different webpack module instances, so the WebpackAssetsManifest plugin (built against @teambit/webpack's copy) gets applied to a Compiler built by webpack-bundler's copy - causing The 'compilation' argument must be an instance of Compilation failures on tag/build for react-based custom envs.

Fix

Source the same types from the packages react/aspect already depend on and actually build with, instead of @teambit/webpack:

  • WebpackConfigTransformer, WebpackConfigDevServerTransformContext → @teambit/webpack.webpack-bundler
  • WebpackConfigWithDevServer → @teambit/webpack.webpack-dev-server
  • WebpackConfigMutator → @teambit/webpack.modules.config-mutator
  • Configuration → webpack directly (matches the existing convention used elsewhere in scopes/react/react/webpack/*)

No behavior change - type-only imports, just re-pointed. @teambit/webpack no longer appears in either package's dependency policy.

Test plan

  • bit tag --build on a react-based custom env (the scenario from e2e/harmony/custom-env-operations.e2e.ts / custom-env-operations-2.e2e.ts) no longer throws the cross-instance webpack error
  • npm view @teambit/react dependencies / @teambit/aspect dependencies no longer lists @teambit/webpack after the next release

…ports

react.env, react.main.runtime, and the app-build files only needed
WebpackConfigTransformer/WebpackConfigMutator/Configuration types from
@teambit/webpack; source them from webpack-bundler, webpack-dev-server,
and modules.config-mutator instead (same for aspect.env). Those packages
already ship the types and are what react/aspect actually bundle with -
depending on @teambit/webpack too pulled in its own webpack instance
(exact 5.97.1 + webpack-assets-manifest), which pnpm resolves separately
from webpack-bundler's floating range, causing cross-instance
"argument must be an instance of Compilation" failures when the plugin
is applied to a compiler built by the other webpack copy.
@GiladShoham
GiladShoham enabled auto-merge (squash) August 14, 2026 17:24
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fix React/Aspect envs pulling @teambit/webpack via type-only imports

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Repoint webpack-related type imports to bundler/dev-server/config-mutator packages already in use.
• Drop accidental runtime dependency on @teambit/webpack from published React/Aspect packages.
• Prevent pnpm multi-webpack-instance build failures (e.g., Compilation instance mismatch).
Diagram

graph TD
  A["react.env.ts"] --> P(["webpack.webpack-bundler"])
  B["react.main.runtime.ts"] --> W{{"webpack (types)"}} --> P
  C["react.application.ts"] --> P
  D["react-app-options.ts"] --> P
  E["apps/web/webpack/mutators.ts"] --> M(["modules.config-mutator"])
  F["webpack.config.env.dev.ts"] --> S(["webpack.webpack-dev-server"])
  G["aspect.env.ts"] --> P

  subgraph Legend
    direction LR
    _file["File"] ~~~ _pkg(["Package"]) ~~~ _ext{{"External"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Fix Bit dependency resolver to ignore type-only imports
  • ➕ Systemic fix prevents similar issues across the repo
  • ➕ Keeps type sources unchanged at call sites
  • ➖ Larger, riskier change with broader blast radius
  • ➖ May require TS AST/build pipeline awareness and extensive validation
2. Keep @teambit/webpack but force single webpack instance (peers/overrides/dedupe)
  • ➕ Avoids changing import sources
  • ➕ May help other multi-instance issues
  • ➖ Still leaves an unnecessary dependency edge from @teambit/react/@teambit/aspect
  • ➖ Fragile across package managers; harder to guarantee for consumers
3. Re-export needed types from @teambit/react (local facade)
  • ➕ Centralizes type API and hides underlying package churn
  • ➕ Future refactors become internal
  • ➖ Adds maintenance surface and potential circular type deps
  • ➖ Still requires choosing a canonical underlying source

Recommendation: Current approach (repoint type-only imports to the exact bundler/dev-server/config-mutator packages already used at runtime) is the smallest, lowest-risk fix and directly removes the dependency edge that caused pnpm to install multiple webpack instances. Consider the resolver-level fix later if this pattern appears broadly, but it’s not necessary to address the immediate build break.

Files changed (7) +11 / -7

Bug fix (7) +11 / -7
aspect.env.tsSource WebpackConfigTransformer type from webpack-bundler +1/-1

Source WebpackConfigTransformer type from webpack-bundler

• Replaces the type-only import of WebpackConfigTransformer from @teambit/webpack with @teambit/webpack.webpack-bundler to avoid pulling @teambit/webpack into the Aspect env dependency graph.

scopes/harmony/aspect/aspect.env.ts

react-app-options.tsRepoint ReactAppOptions transformer type import to webpack-bundler +1/-1

Repoint ReactAppOptions transformer type import to webpack-bundler

• Updates WebpackConfigTransformer type import to come from @teambit/webpack.webpack-bundler, keeping the public options type aligned with the bundler actually used.

scopes/react/react/apps/web/react-app-options.ts

react.application.tsUse webpack-bundler WebpackConfigTransformer type in ReactApp +1/-1

Use webpack-bundler WebpackConfigTransformer type in ReactApp

• Switches the WebpackConfigTransformer type import to @teambit/webpack.webpack-bundler, removing the transitive @teambit/webpack dependency from the React application implementation.

scopes/react/react/apps/web/react.application.ts

mutators.tsImport WebpackConfigMutator type from modules.config-mutator +1/-1

Import WebpackConfigMutator type from modules.config-mutator

• Replaces the WebpackConfigMutator type import source with @teambit/webpack.modules.config-mutator to avoid referencing @teambit/webpack for types.

scopes/react/react/apps/web/webpack/mutators.ts

react.env.tsMove webpack transformer/context type imports to webpack-bundler +4/-1

Move webpack transformer/context type imports to webpack-bundler

• Updates WebpackConfigTransformer and WebpackConfigDevServerTransformContext type imports to @teambit/webpack.webpack-bundler, ensuring the env’s webpack types match the bundler package used at runtime.

scopes/react/react/react.env.ts

react.main.runtime.tsUse upstream webpack Configuration type and bundler transformer types +2/-1

Use upstream webpack Configuration type and bundler transformer types

• Replaces Configuration type import from @teambit/webpack with webpack, and WebpackConfigTransformer with @teambit/webpack.webpack-bundler, eliminating @teambit/webpack as a runtime dependency trigger.

scopes/react/react/react.main.runtime.ts

webpack.config.env.dev.tsSource WebpackConfigWithDevServer type from webpack-dev-server +1/-1

Source WebpackConfigWithDevServer type from webpack-dev-server

• Updates the WebpackConfigWithDevServer type import to @teambit/webpack.webpack-dev-server, matching the dev-server package used by the React env.

scopes/react/react/webpack/webpack.config.env.dev.ts

@github-actions github-actions Bot mentioned this pull request Aug 14, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@GiladShoham
GiladShoham merged commit 671aa23 into master Aug 14, 2026
16 checks passed
@GiladShoham
GiladShoham deleted the fix/react-env-drop-teambit-webpack-dep branch August 14, 2026 17:59
GiladShoham added a commit that referenced this pull request Aug 16, 2026
@teambit/node, react, aspect, env: 1.0.1102 -> 1.0.1105
@teambit/mdx, readme: 1.0.1103 -> 1.0.1106

react/aspect no longer depend on @teambit/webpack after #10620.
GiladShoham added a commit that referenced this pull request Aug 16, 2026
… the core aspect

WebpackMain.createBundler/createDevServer, the WebpackBundler/WebpackDevServer
classes, and their config factories duplicated what @teambit/webpack.webpack-bundler
and @teambit/webpack.webpack-dev-server now do (react/aspect/node envs build
through those packages directly, not this aspect - see #10620). Nothing in the
codebase calls createBundler/createDevServer anymore.

Also drops generateExposePeersTransformer (already marked dead code) and its
only helpers (get-exposed-rules, resolve-peer).

Kept: the type exports, WebpackConfigMutator/Configuration re-exports, the
thin transformer/plugin/fallback re-exports, and the WebpackMain class itself
(gutted, so the aspect still loads for backward compatibility).
GiladShoham added a commit that referenced this pull request Aug 16, 2026
…#10624)

## Summary
react/node/aspect envs build with `@teambit/webpack.webpack-bundler` and
`@teambit/webpack.webpack-dev-server` directly now (#10610), not the
`teambit.webpack/webpack` core aspect. Depending on both means pnpm
resolves two independently-versioned webpack instances - the exact root
cause behind the `instanceof Compilation` failures fixed in #10620.

This PR only adds `@deprecated` JSDoc to the now-superseded surface
(`WebpackMain.createBundler`/`createDevServer`/`mergeConfig`, the
`WebpackBundler`/`WebpackDevServer` classes, and the various
type/utility re-exports) so anyone still importing from
`@teambit/webpack` gets a signal to move to the standalone packages. No
code is removed and no behavior changes - purely additive, safe to merge
on its own.

A follow-up PR deletes the deprecated code once callers have had a
chance to migrate (tracked separately, alongside
https://bit.cloud/teambit/webpack/~change-requests/decouple-webpack-bundler-from-webpack-aspect).

## Test plan
- [x] `npm run lint` passes (tsc + oxlint)
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