SwaggerEditor@5: `PACKAGE_VERSION` is not substituted in the UMD build, breaking the Monaco editor (regression in 5.8.6)
Title: SwaggerEditor@5: PACKAGE_VERSION is not substituted in the UMD build, breaking the Monaco editor (regression in 5.8.6)
Q&A
Q: Have you tried the latest version? Yes — reproduced on 5.8.9.
Content & configuration
Swagger-Editor configuration: none (default props)
Swagger/OpenAPI definition: any — the failure occurs while the editor renders, before a definition matters.
Describe the bug you're encountering
Since 5.8.6, the UMD bundle references build-time constants that are never substituted, so the splash screen throws:
ReferenceError: PACKAGE_VERSION is not definedReact's error boundary catches this, so nothing appears as an uncaught error — but the Monaco editor never mounts. .monaco-editor is absent and the editing pane is blank. To a user the editor simply looks broken, with no obvious error.
This is a regression from c1664ad (#5874, "display the correct version for the package consumers"), released in 5.8.6. That change made SplashScreen.jsx render PACKAGE_VERSION directly and added buildDefines() to vite/shared.js — but vite.config.umd.js never picked it up.
vite.config.umd.js is the only build config with no define block. It imports only logger and sharedOnwarn:
import { logger, sharedOnwarn } from './vite/shared.js';whereas vite.config.js and vite.config.app.js both apply buildDefines(). As a result the UMD bundle ships the literal identifiers.
I bisected this across releases:
| Version | .monaco-editor renders |
Notes |
|---|---|---|
| 5.8.4 | yes | no unguarded reference |
| 5.8.5 | yes | last good release |
| 5.8.6 | no | regression introduced |
| 5.8.7 | no | |
| 5.8.8 | no | |
| 5.8.9 | no |
Related gotcha: PACKAGE_VERSION cannot be defined on its own. VersionsPlugin.afterLoad guards only on typeof PACKAGE_VERSION, and that branch then reads GIT_COMMIT, GIT_DIRTY and BUILD_TIME. Defining just PACKAGE_VERSION opens the branch and moves the failure to GIT_COMMIT is not defined — so all four have to be handled together.
Steps to reproduce
Serve this over HTTP with react, react-dom and [email protected]'s dist/umd/ alongside it. The two shim lines only work around the separate require/process failure, so that this defect is the one observed:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /></head>
<body>
<div id="swagger-editor"></div>
<script src="./react.production.min.js" crossorigin></script>
<script src="./react-dom.production.min.js" crossorigin></script>
<script>
window.require = (id) => ({ react: React, "react-dom": ReactDOM })[id];
window.process = { env: { NODE_ENV: "production" } };
</script>
<script src="./umd/swagger-editor.js" crossorigin></script>
<script>
ReactDOM.render(
React.createElement(SwaggerEditor, {}),
document.querySelector("#swagger-editor"),
);
</script>
</body>
</html>Open the console and inspect the DOM for .monaco-editor.
Expected behavior
The UMD build substitutes PACKAGE_VERSION, GIT_COMMIT, GIT_DIRTY and BUILD_TIME at build time — as the ESM and app builds do — and the Monaco editor mounts.
Actual behavior
Four ReferenceError: PACKAGE_VERSION is not defined errors are logged via React's error boundary, and .monaco-editor is never created.
Possible solution
Apply the shared defines to the UMD config, mirroring the other two:
import { buildDefines, logger, sharedOnwarn } from './vite/shared.js';
// ...within mainConfig
define: buildDefines(),It may also be worth guarding the splash screen with typeof PACKAGE_VERSION === 'undefined' so a missing define degrades gracefully instead of taking the editor down.
Environment
- Swagger-Editor version: 5.8.9 (UMD / standalone); regression introduced in 5.8.6
- OS: macOS
- Browser: Chrome (headless and normal)
- Framework: none — plain
<script>tags
Source: swagger-api/swagger-editor