Skip to content

@cloudflare/vite-plugin without node compat breaks due to "node:module" imported from "rolldown:runtime" #248

Open
@hi-ogawa

Description

@hi-ogawa

Describe the bug

The reproduction with @cloudflare/vite-plugin is found in https://github.com/hi-ogawa/reproductions/tree/main/rolldown-runtime-external-side-effect-cf. I briefly checked the plugin and made a minimal repro in https://github.com/hi-ogawa/reproductions/tree/main/rolldown-runtime-external-side-effect

    // mini version of
    // https://github.com/cloudflare/workers-sdk/blob/f45208ca588d0565fa4e3abcee7be3974a1ef85d/packages/vite-plugin-cloudflare/src/index.ts#L799
    {
      name: 'repro',
      enforce: 'pre',
      resolveId(source, importer, options) {
        if (source === 'node:module') {
          console.log("[resolveId]", { source, importer });
          return {
            id: source,
            external: true,
          };
        }
      },
    }

@cloudflare/vite-plugin uses resolveId to track unsupported node builtin import and shows a warning. This logic is also applied to rolldown:runtime on rolldown-vite and thus causing an warning and also runtime error due to import "node:module" being left in the server build.

I'm raising an issue here as I wasn't sure if this is something that should be addressed on rolldown/vite or plugin side. If we suggest cloudflare plugin side to add rolldown specific logic, then, for example build.rollOptions.platform: "neutral" avoids node:module from rolldown runtime and that seems to work on my use case (hi-ogawa/vite-plugins#931)

  environments: {
    ssr: {
      build: {
        rollupOptions: {
          platform: "neutral",
        }
      }
    }
  }

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/rolldown-runtime-external-side-effect-cf
https://github.com/hi-ogawa/reproductions/tree/main/rolldown-runtime-external-side-effect

Steps to reproduce

See READE.md in repro

System Info

System:
    OS: Linux 6.14 Arch Linux
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 18.32 GB / 31.05 GB
    Container: Yes
    Shell: 5.2.37 - /usr/bin/bash
  Binaries:
    Node: 22.14.0 - ~/.volta/tools/image/node/22.14.0/bin/node
    npm: 10.9.2 - ~/.volta/tools/image/node/22.14.0/bin/npm
    pnpm: 10.11.1 - ~/.volta/tools/image/node/22.14.0/bin/pnpm
    bun: 1.2.4 - ~/.local/bin/bun
  Browsers:
    Brave Browser: 137.1.79.119
    Chromium: 136.0.7103.113
  npmPackages:
    rolldown-vite:  6.3.18

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions