cloudflare deployment error: No such module 'node:http' imported from 'chunks/nitro/nitro.mjs

I get the error below when I try to deploy to cloudflare pages:

Error: Failed to publish your Function. Got error: Uncaught Error: No such module "node:http".
  imported from "chunks/nitro/nitro.mjs"


Has anyone experienced this? I followed the deployment instruction from the docs https://tanstack.com/start/latest/docs/framework/react/hosting#cloudflare-pages

// app.config.ts
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from '@tanstack/start/config';
import { cloudflare } from 'unenv';
import tsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
  server: {
    preset: 'cloudflare-pages',
    unenv: cloudflare,
  },
  vite: {
    plugins: [
      tsConfigPaths({
        projects: ['./tsconfig.json'],
      }),
      tailwindcss(),
    ],
  },
});

wrangler.toml
name = "my-app"
pages_build_output_dir = "./dist"
compatibility_flags = ["nodejs_compat"]
compatibility_date = "2024-11-13"

package.json
{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "dev": "vinxi dev",
    "build": "vinxi build",
    "start": "vinxi start"
  },
  "dependencies": {
    "@tanstack/react-router": "1.105.0",
    "@tanstack/start": "1.105.3",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "unenv": "^1.10.0",
    "vinxi": "0.5.3"
  },
  "devDependencies": {
    "@tailwindcss/vite": "^4.0.6",
    "@types/react": "^19.0.9",
    "@types/react-dom": "^19.0.3",
    "@vitejs/plugin-react": "^4.3.4",
    "typescript": "5.7.3",
    "vite-tsconfig-paths": "5.1.4"
  }
}

Is it normal to have imports like below in dist/_worker.js/chunks/nitro/nitro.mjs ?
import * as node_http from 'node:http';
import * as node_https from 'node:https';
import * as node_zlib from 'node:zlib';
import * as node_stream from 'node:stream';
import { PassThrough, Readable as Readable$1 } from 'node:stream';
import * as node_buffer from 'node:buffer';

...
Hosting is the process of deploying your application to the internet so that users can access it. This is a critical part of any web development project, ensuring your application is available to the...
Was this page helpful?