fix: replace require() with dynamic import() in vite config for ESM compatibility#858
Merged
Merged
Conversation
bjnewman
approved these changes
Apr 28, 2026
jordan-a-young
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
config.bundler = 'vite'in a project installed from npm, the build and dev server fail immediately:Root cause
vite.config.jsusescreateRequire()to load 6 packages that are all ESM-only:vite-tsconfig-pathsvite-plugin-static-copyvite-plugin-checker@vitejs/plugin-react-swc/@vitejs/plugin-react@availity/workflow-logger(switched from CJS to ESM in v8.0.0)This wasn't caught in the monorepo because
workspace:*resolution handles the CJS/ESM boundary transparently.The bug only manifests when consuming the published packages from npm.
Fix
buildViteConfigasync, replace allrequire()withawait import()buildViteProductionConfigasync,awaitthe base configawaitto callers inbuild.jsandstart.js(both already async)Testing
Added 2 tests to
workflowConfigs.spec.jsthat callbuildViteConfig(settings)andbuildViteProductionConfig(settings)without mocking the plugin imports. Verified tests fail without the fix andpass with it.