Skip to content

Avoid collecting nodejs_compat warnings during dependency optimization#12381

Merged
petebacondarwin merged 4 commits intomainfrom
james/nodejs-compat-warnings
Feb 3, 2026
Merged

Avoid collecting nodejs_compat warnings during dependency optimization#12381
petebacondarwin merged 4 commits intomainfrom
james/nodejs-compat-warnings

Conversation

@jamesopstad
Copy link
Copy Markdown
Contributor

@jamesopstad jamesopstad commented Feb 3, 2026

Fixes #12194.

Avoid collecting nodejs_compat warnings during dependency optimization.

Previously, a custom plugin was provided during dependency optimization to collect warnings when Node.js built-ins were imported and the nodejs_compat flag was not enabled.
Because optimized dependencies are cached, the warning was only displayed when dependencies changed.
Additionally, it sometimes included false positives from dependencies that were no longer used.
We now always externalize Node.js built-ins during dependency optimization and collect the warnings at runtime.
This is more consistent with how warnings are collected for direct imports of Node.js built-ins.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@jamesopstad jamesopstad requested a review from a team as a code owner February 3, 2026 09:29
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 1381188

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Feb 3, 2026

Claude finished @jamesopstad's task —— View job


Changeset Review

Todo List

  • Read changeset guidelines from .changeset/README.md
  • Review .changeset/sharp-rice-double.md
  • Validate version type, changelog quality, and formatting
  • Check for cute animal images
  • Post final review results

All changesets look good

The changeset in .changeset/sharp-rice-double.md passes all validation criteria:

  1. Version Type: patch is appropriate for a bug fix ✓
  2. Changelog Quality: Clear description with context about the problem and solution ✓
  3. Markdown Headers: No h1/h2/h3 headers present ✓
  4. Analytics: No analytics collection changes ✓
  5. Experimental Features: Not applicable ✓

The changeset provides a good explanation of the issue (warnings only shown when dependencies changed, false positives) and the solution (externalize Node.js built-ins during optimization, collect warnings at runtime).


@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 3, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12381

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12381

miniflare

npm i https://pkg.pr.new/miniflare@12381

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12381

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12381

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12381

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12381

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12381

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12381

wrangler

npm i https://pkg.pr.new/wrangler@12381

commit: 1381188

test("displays warnings if Node.js built-ins are imported and the `nodejs_compat` flag is not enabled", async () => {
const proc = await runLongLived("pnpm", "dev", projectPath);
expect(await proc.exitCode).not.toBe(0);
const errorLogs = proc.stderr.replaceAll("\\", "/");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this + checking the link has real added value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what this means.

handler(source, importer) {
return resolveId(this.environment.name, source, importer);
// Fallback for when filter is not applied
// TODO: remove when we drop support for Vite 6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggest: TODO -> create a GH issue and link it here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This didn't change in this PR (the code was just moved) and we have a lot of these sprinkled around so it would add noise to change them here. I'm creating tickets for them.

nodeJsCompatWarningsMap.get(workerConfig);
nodeJsCompatWarnings?.registerImport(source, importer);

// Mark this path as external to avoid messy unwanted resolve errors.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would that be right here?

Suggested change
// Mark this path as external to avoid messy unwanted resolve errors.
// Mark this module as external to avoid messy unwanted resolve errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that's right, although this also didn't change in this PR. I can change it though.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional flags.

Open in Devin Review

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

LGTM high level, I don't know this code base enough to feel confident to approve

},
plugins: [
// In Vite 8, `require` calls are not automatically replaced when the format is ESM and `platform` is `neutral`
// @ts-expect-error: added in Vite 8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this not mean this would error in Vite before v8?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although I see this is just moved code, so I guess it works already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn't execute pre-v8 because isRolldown will be false.

},
plugins: [
// In Vite 8, `require` calls are not automatically replaced when the format is ESM and `platform` is `neutral`
// @ts-expect-error: added in Vite 8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although I see this is just moved code, so I guess it works already.

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 3, 2026
@petebacondarwin petebacondarwin merged commit 98283fa into main Feb 3, 2026
44 checks passed
@petebacondarwin petebacondarwin deleted the james/nodejs-compat-warnings branch February 3, 2026 11:13
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[@cloudflare/vite-plugin] Unexpected Node.js imports

4 participants