Skip to content

Add option to gen sourcemaps for handler.mjs #824

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-radios-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": minor
---

add option to generate sourcemap for handler.mjs
9 changes: 9 additions & 0 deletions packages/cloudflare/src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function defineCloudflareConfig(config: CloudflareOverrides = {}): OpenNe
edgeExternals: ["node:crypto"],
cloudflare: {
useWorkerdCondition: true,
sourcemap: false,
},
dangerous: {
enableCacheInterception,
Expand Down Expand Up @@ -154,6 +155,14 @@ interface OpenNextConfig extends AwsOpenNextConfig {
*/
useWorkerdCondition?: boolean;

/**
* Whether to genereate a sourcemap for the bundled server.
*
*
* @default false
*/
sourcemap?: boolean;

/**
* Disable throwing an error when the config validation fails.
* This is useful for overriding some of the default provided by cloudflare.
Expand Down
1 change: 1 addition & 0 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
minifySyntax: !debug,
legalComments: "none",
metafile: true,
sourcemap: getOpenNextConfig(buildOpts).cloudflare?.sourcemap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can always generate the source maps.

The Next build dominates the build time so the build time should not change a lot

Suggested change
sourcemap: getOpenNextConfig(buildOpts).cloudflare?.sourcemap,
sourcemap: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just interested in figuring out a way to have server side sourcemaps for readable stack traces on cloudflare. Trying to figure out how to make this happen.

// Next traces files using the default conditions from `nft` (`node`, `require`, `import` and `default`)
//
// Because we use the `node` platform for this build, the "module" condition is used when no conditions are defined.
Expand Down