Commit 02d68f8
committed
fix: provide module/exports in VM sandbox for Node.js 25+ compatibility
Templates whose child compilation output is a CommonJS module (for
example Rspack's HtmlWebpackPlugin child compilation, which wraps the
evaluated template in `module.exports = ...`) were failing at evaluation
time with `ReferenceError: module is not defined` under Node.js 25+.
In 5.6.5 the VM context was switched away from a `...global` spread
because spreading `global` on Node 25 throws once `localStorage` is
touched without `--localstorage-file`. The replacement clone only
exposes the standard globals plus `require`, so any CommonJS-wrapped
source that assigned to `module.exports` hit the ReferenceError.
Provide a throwaway `module = { exports: {} }` pair (plus `exports`
aliasing it) in the sandbox so CommonJS-style outputs can evaluate
without assuming the host Node version populates them.
Refs: PR jantimon#1880, facebook/docusaurus#115451 parent 0d1ff98 commit 02d68f8
3 files changed
Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
643 | 647 | | |
644 | 648 | | |
645 | 649 | | |
646 | 650 | | |
647 | 651 | | |
| 652 | + | |
| 653 | + | |
648 | 654 | | |
649 | 655 | | |
650 | 656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3853 | 3853 | | |
3854 | 3854 | | |
3855 | 3855 | | |
| 3856 | + | |
| 3857 | + | |
| 3858 | + | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
3856 | 3868 | | |
0 commit comments