Skip to content

Fix Vite 8 library React imports - #300

Open
krowvin wants to merge 1 commit into
mainfrom
fix/vite8-library-bundle
Open

Fix Vite 8 library React imports#300
krowvin wants to merge 1 commit into
mainfrom
fix/vite8-library-bundle

Conversation

@krowvin

@krowvinkrowvin commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • configure the Vite 8 library build to convert external React require() calls into browser-compatible ESM imports
  • use the current rolldownOptions configuration name
  • declare @babel/parser, which the Lighthouse route extraction script imports directly
  • verify the generated ESM bundle in the React 18/19 compatibility workflow

Background

@LaurenAllin reported in USACE-WaterManagement/groundwork-water#319 that updating Groundwork and Groundwork Water produced a browser error calling require("react"), and that returning to an earlier Groundwork version restored the application.

I reproduced that finding locally in a fresh Vite application with Groundwork Water 4.0.0 and Groundwork 4.3.1. The application built, but the browser rendered a blank page with the same require("react") error. The generated Groundwork ESM bundle contained Rolldown's runtime CommonJS fallback around React.

Vite 8 provides esmExternalRequirePlugin for this migration case. Applying it to Groundwork's React peer dependencies keeps React external while converting those calls to standard ESM imports.

Local verification

  • npm test -- --run - 8 tests passed
  • npm run lint
  • React 18: library build, bundle verification, and docs build
  • React 19: library build, bundle verification, and docs build
  • npm pack --dry-run
  • linked this Groundwork branch into a clean Groundwork Water checkout
  • built the linked Groundwork Water library and documentation site
  • served the linked production documentation build locally with React deduplicated for the symlinked peer dependencies; the page rendered with styles and no browser console errors

The bundle check fails if a future ESM build reintroduces the browser-side CommonJS fallback or a direct React require() call.

Related: USACE-WaterManagement/groundwork-water#319

@github-actions

Copy link
Copy Markdown

Please set a versioning label of either major-bump, minor-bump, or patch-bump to the pull request.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@krowvin