Commit 49329fa
committed
fix(cloudflare): alias debug to obug-backed shim in server environments
Fixes `ReferenceError: module is not defined` on every request in
`astro dev` with the Cloudflare adapter. The CJS `debug` package is
pulled transitively by `micromark`, `stylus`, and many other common
npm packages; when `@cloudflare/vite-plugin` loads it in the workerd
runner used for `astro dev`, SSR and prerendering, the top-level
`module.exports` reference crashes because `module` is not a global
there.
Extends the approach from #15565 (which replaced astro core's direct
`debug` usage with `obug`) to the downstream dependency graph by
aliasing `debug` to an internal shim that re-exports `obug` with a
default export, so consumers that do `import debug from "debug"` or
`require("debug")` keep working after the alias is applied.
The alias is added at the top-level `vite.resolve.alias` so it
propagates to every Vite environment created by the adapter (astro,
ssr, prerender).1 parent 7959798 commit 49329fa
5 files changed
Lines changed: 48 additions & 19 deletions
File tree
- .changeset
- packages/integrations/cloudflare
- src
- shims
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
209 | 219 | | |
210 | 220 | | |
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
214 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
215 | 228 | | |
216 | 229 | | |
217 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments