Skip to content

fix: tree-shake Node.js code from browser bundles#415

Closed
joshuaellis wants to merge 0 commit intomodule-federation:mainfrom
joshuaellis:fix/issue-274
Closed

fix: tree-shake Node.js code from browser bundles#415
joshuaellis wants to merge 0 commit intomodule-federation:mainfrom
joshuaellis:fix/issue-274

Conversation

@joshuaellis
Copy link
Contributor

@joshuaellis joshuaellis commented Feb 17, 2026

Description

ENV_TARGET exists in the @module-federation/sdk package to infer tree shaking e.g. if you set it to web then the node branches will be eliminated in theory (there's a PR to change this from func to constant to improve the tree-shaking see Notes section). We now have a target option that will deliver this to the rest of the setup correctly, it falls back to web if not set unless build.ssr is set in which we set it to node these defaults align with vite's default behaviours.

Converts the virtual modules to be ESM in build mode to enable rollup to tree-shake more effectively, however Dev mode still uses CJS because syntheticNamedExports are not respected since vite doesn't use rollup for dev & import { useState } from 'react' would thereby fail. This also seems to be some work required to support vite7 identified in #369 which is nice.

Related Issues

Notes

This PR requires:

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.

[Bug]: NodeJS vm code + 'eval' needlessly included in web bundle (Causing CSP errors)

1 participant