Skip to content

Conversation

@bratvanov
Copy link
Contributor

The preview script in my project (opennextjs-cloudflare build && opennextjs-cloudflare preview) was plagued by tens of esbuild warnings coming from third-party dependencies, and was extremely noisy.

Some of the warnings were coming from the opennextjs-cloudflare preview command – mostly direct-eval warnings. I was able to silence them by passing --log-level error to the opennextjs-cloudflare preview command.

However, I didn't find a way to configure logging in the opennextjs-cloudflare build command. Therefore, this PR adds the ability to completely override the esbuild config in the open-next.config.ts, like that:

import { defineCloudflareConfig } from "@opennextjs/cloudflare/config";

export default defineCloudflareConfig({
  esbuild: {
    bundleServer: (options) => ({
      ...options,
      logOverride: {
        ...options.logOverride,
        "impossible-typeof": "silent",
        "duplicate-object-key": "silent",
      },
    }),
  },
});

You should be able to override/re-config any aspect of esbuild, not just superficial logging overrides, e.g:

esbuild: {
  bundleServer: (options) => ({
    ...options,
    external: [
      ...(options.external ?? []),
      "sharp", // this package is huge; we let another runtime handle it instead
    ],
    define: {
      ...options.define,
      "process.env.SENTRY_RELEASE": JSON.stringify(
        process.env.SENTRY_RELEASE ?? "dev"
      ),
    },
  }),
},

Please let me know what you think. Thanks!

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2025

⚠️ No Changeset found

Latest commit: 54d1838

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 20, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@955

commit: 54d1838

@bratvanov
Copy link
Contributor Author

bratvanov commented Oct 21, 2025

I realized that even with the above changes patching opennextjs-cloudflare build – the warnings will not be suppressed when running the equivalent build command from wrangler (wrangler build).

Therefore, I wonder if it wouldn't be better to propose and consider adding --log-level support for the build command into wrangler instead (and also to wrangler deploy, as it also surfaces esbuild warnings with no way to silence them)?

While the warnings are harmless, I have extensively integrated AI coding agents not just for local development, but also in CI/CD, and constantly burning through thousands of tokens re-processing the same benign warnings from external packages that I have no control over is adding a real financial cost.

As it stands, currently only wrangler dev (and by extension, opennextjs-cloudflare preview) supports the --log-level flag, which in my opinion, is insufficient.

For the time being, I've implemented custom build/deploy script wrappers that filter the warnings from the original output, but this feels like a hack, as it's fragile and may break when/if the format of the warnings change. I'm open to suggestions on how to best tackle this. Thanks!

@bratvanov bratvanov marked this pull request as draft October 21, 2025 16:11
@bratvanov bratvanov changed the title add EsbuildOverride to defineCloudflareConfig add EsbuildOverride to defineCloudflareConfig (change build logging level) Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant