Skip to content

fix: replace require() with dynamic import() in vite config for ESM compatibility#858

Merged
jordan-a-young merged 1 commit into
Availity:masterfrom
Viou:fix/vite-esm-require
Apr 29, 2026
Merged

fix: replace require() with dynamic import() in vite config for ESM compatibility#858
jordan-a-young merged 1 commit into
Availity:masterfrom
Viou:fix/vite-esm-require

Conversation

@Viou
Copy link
Copy Markdown

@Viou Viou commented Apr 28, 2026

Problem

When using config.bundler = 'vite' in a project installed from npm, the build and dev server fail immediately:

Error [ERR_REQUIRE_ESM]: require() of ES Module .../vite-tsconfig-paths/dist/index.js
from .../node_modules/@availity/workflow/vite.config.js not supported.

Root cause

vite.config.js uses createRequire() to load 6 packages that are all ESM-only:

  • vite-tsconfig-paths
  • vite-plugin-static-copy
  • vite-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

  • Make buildViteConfig async, replace all require() with await import()
  • Make buildViteProductionConfig async, await the base config
  • Add await to callers in build.js and start.js (both already async)
  • Add regression tests that import and call the real vite configs

Testing

Added 2 tests to workflowConfigs.spec.js that call buildViteConfig(settings) and
buildViteProductionConfig(settings) without mocking the plugin imports. Verified tests fail without the fix and
pass with it.

@jordan-a-young jordan-a-young merged commit ef6bf47 into Availity:master Apr 29, 2026
8 checks passed
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.

3 participants