Commit ad66e94
committed
fix: eliminate runtime require()/exports.foo bombs in ESM modules
The previous merge resolution caught the obvious `require()` calls in
files with conflict markers, but several develop-side files use bare
`require()` or `exports.foo = ...` outside of conflict zones. These
compile fine under tsc (which is permissive about CJS-shape syntax in
ESM modules) but throw at runtime as soon as the module is loaded by
Node's ESM loader: `ReferenceError: require/exports is not defined in
ES module scope`.
That's what the CI surfaced — every job that boots the server or builds
the admin UI (which imports the server modules to dump the OpenAPI
spec) was failing on:
src/node/utils/Settings.ts:1346 `require('../../package.json')`
src/node/hooks/express/openapi.ts:874 `exports.generateDefinitionForVersion = ...`
Fixed:
- Settings.ts:1346 — replaced the inline `require(...).version` with the
existing ESM-safe `getEpVersion()` helper (which already uses the
module's createRequire bridge on line 884). Same value, no duplication.
- server.ts:193 — `require('./updater')` → `await import('./updater/index.js')`
for the optional markBootHealthy() call.
- ExportHandler.ts — added a createRequire bridge and replaced the four
inline `require()` calls (sofficeAvailable, ExportSanitizeHtml,
html-to-docx, ExportPdfNative) with ESM imports where possible.
- ImportHandler.ts — added static ESM imports for ImportDocxNative and
ExportSanitizeHtml; dropped the three inline `require()` calls.
- ExportPdfNative.ts, ImportDocxNative.ts — added createRequire bridges
for the top-level CJS-only npm package requires (pdfkit, mammoth, jszip).
These packages publish CJS entries that don't round-trip cleanly through
ESM default-import interop under tsx; the bridge is the minimum-risk fix.
- adminsettings.ts — replaced inline `require('AuthorManager')` with a
static `import * as authorManager`.
- pad_editbar.ts — replaced `require('./pad_mode')` with `await import(...)`
inside the showTimeSlider click handler (which is already async-capable).
- openapi.ts:874-875 — `exports.X = X; exports.Y = Y;` → `export {X, Y};`.
- openapi-admin.ts — dropped the redundant `exports.expressPreSession =
expressPreSession;` (the function is already `export const`) and the
duplicate `exports.generateAdminDefinition = generateAdminDefinition;`
(also already `export const` on the declaration line).
Verified locally:
- `pnpm run ts-check` passes.
- `admin/scripts/dump-spec.ts` — the script that booted the failing
`dump-spec.ts failed with exit code 1` in CI — now runs to completion
and writes a 128 KB spec.1 parent 95f753c commit ad66e94
10 files changed
Lines changed: 32 additions & 20 deletions
File tree
- src
- node
- handler
- hooks/express
- utils
- static/js
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
| |||
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
99 | | - | |
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| |||
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
108 | | - | |
| 115 | + | |
109 | 116 | | |
110 | 117 | | |
111 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
160 | | - | |
161 | | - | |
| 162 | + | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| |||
281 | 283 | | |
282 | 284 | | |
283 | 285 | | |
284 | | - | |
285 | | - | |
| 286 | + | |
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
311 | | - | |
312 | | - | |
313 | 312 | | |
314 | 313 | | |
315 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
157 | | - | |
158 | 156 | | |
159 | 157 | | |
160 | 158 | | |
| |||
179 | 177 | | |
180 | 178 | | |
181 | 179 | | |
182 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | | - | |
875 | | - | |
| 874 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
193 | | - | |
| 192 | + | |
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
3 | 8 | | |
4 | 9 | | |
5 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1343 | 1343 | | |
1344 | 1344 | | |
1345 | 1345 | | |
1346 | | - | |
1347 | 1346 | | |
1348 | | - | |
| 1347 | + | |
1349 | 1348 | | |
1350 | 1349 | | |
1351 | 1350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
524 | | - | |
| 524 | + | |
| 525 | + | |
525 | 526 | | |
526 | 527 | | |
527 | 528 | | |
| |||
0 commit comments