-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(cloudflare): alias debug to obug-backed shim in server environments
#16569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nathanredblur
wants to merge
1
commit into
withastro:main
from
nathanredblur:fix/cloudflare-debug-alias
+48
−19
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@astrojs/cloudflare': patch | ||
| --- | ||
|
|
||
| Fixes `ReferenceError: module is not defined` on every request when running `astro dev` with the Cloudflare adapter. The error was triggered whenever a page's dependency graph pulled in the CJS `debug` package (transitively via `micromark`, `stylus`, and many other common npm packages). The adapter now aliases `debug` to an internal ESM shim backed by `obug` in the `ssr`, `astro`, and `prerender` Vite environments, so the workerd runner used by `@cloudflare/vite-plugin` no longer hits the missing `module` global. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Drop-in ESM replacement for the `debug` package, used via Vite's | ||
| // `resolve.alias` in server environments that run under workerd | ||
| // (astro dev + @cloudflare/vite-plugin). | ||
| // | ||
| // The original `debug` package references `module.exports` at the top | ||
| // level of its CJS entrypoint, which throws `ReferenceError: module is | ||
| // not defined` when @cloudflare/vite-plugin loads it in the Workers | ||
| // runner. `obug` (https://www.npmjs.com/package/obug) is an ESM fork | ||
| // with the same behavior but exposes only named exports; this shim | ||
| // re-exposes a default export so consumers that do | ||
| // `import debug from "debug"` or `const debug = require("debug")` | ||
| // keep working after the alias is applied. | ||
| import { createDebug, disable, enable, enabled, namespaces } from 'obug'; | ||
|
|
||
| export default createDebug; | ||
| export { createDebug, disable, enable, enabled, namespaces }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on
obug's README,obugv2 is not a drop-in replacement fordebug. Addingresolvehere might break users' apps in unexpected ways. I'd recommend letting users do the replacement themselves, not in the@astro/cloudflarepackage