withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.03k stars 2.43k forks source link

Cloudflare Adapter unable to resolve `node:fs` #6529

Closed jackcarey closed 1 year ago

jackcarey commented 1 year ago

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

Cloudflare v6.2.0

What package manager are you using?

npm

What operating system are you using?

Windows & CF Workers

What browser are you using?

Chrome

Describe the Bug

Here's the info I think is needed:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import critters from "astro-critters";
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  site: 'https://astro-site.pages.dev/',
  experimental: { assets: true },
  integrations: [mdx(), tailwind(), sitemap(), critters(), compress()],
  output: "server",
  adapter: cloudflare({ mode: 'directory' }),
  // output: "static",
});
//package.json
{
    "name": "astro-site",
    "type": "module",
    "version": "0.1.1",
    "scripts": {
        "dev": "astro dev --verbose",
        "start": "astro dev",
        "build": "astro build",
        "build-verbose": "astro build --verbose",
        "preview": "astro preview",
        "preview-wrangler": "wrangler pages dev ./dist",
        "wrangler-deploy": "wrangler",
        "astro": "astro"
    },
    "dependencies": {
        "@astrojs/cloudflare": "^6.2.0",
        "@astrojs/mdx": "^0.17.2",
        "@astrojs/sitemap": "^1.1.0",
        "@astrojs/tailwind": "^3.0.1",
        "astro": "^2.1.2",
        "astro-compress": "^1.1.33",
        "astro-critters": "^1.1.31",
        "tailwindcss": "^3.2.7",
        "wrangler": "^2.12.2"
    },
    "devDependencies": {
        "@types/node": "^18.15.1"
    }
}

and the error I am receiving:

10:38:47 [build] Rearranging server assets...
// the output of the @astro/compress integration appears here
Successfully compressed a total of 1 SVG file for 1.15 KB.
X [ERROR] Could not resolve "node:fs"

    dist/$server_build/_worker.mjs:1:322:
      1 │ ...mport"string-width";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/_worker.mjs:1:338:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "os"

    dist/$server_build/_worker.mjs:1:366:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/_worker.mjs:1:377:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/_worker.mjs:1:389:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/_worker.mjs:1:406:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/_worker.mjs:1:421:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";const isNode="obj... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/_worker.mjs:1:444:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";const isNode="object"==typeof process&&"[... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"...
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:280:
      1 │ ...idth";import"slash";import"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:296:
      1 │ ...port"html-escaper";import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:324:
      1 │ ...import"node:fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";impo... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs"

    dist/$server_build/chunks/astro.451db360.mjs:1:254:
      1 │ ...{escape}from"html-escaper";import{promises}from"node:fs";import{isMainThread}from"node:worker_threads";... 
        ╵                                                   ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:335:
      1 │ ...fs";import"node:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_th... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:worker_threads"

    dist/$server_build/chunks/astro.451db360.mjs:1:288:
      1 │ ...es}from"node:fs";import{isMainThread}from"node:worker_threads";import{cpus}from"os";import{fileURLToPat... 
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~

  The package "node:worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:347:
      1 │ ...e:worker_threads";import"os";import"url";import"node:url";import"module";import"worker_threads";import"... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "os"

    dist/$server_build/chunks/astro.451db360.mjs:1:326:
      1 │ ...nThread}from"node:worker_threads";import{cpus}from"os";import{fileURLToPath as fileURLToPath$1}from"url... 
        ╵                                                      ~~~~

  The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:364:
      1 │ ...";import"os";import"url";import"node:url";import"module";import"worker_threads";import"node:fs/promises... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "url"

    dist/$server_build/chunks/astro.451db360.mjs:1:375:
      1 │ ..."os";import{fileURLToPath as fileURLToPath$1}from"url";import{pathToFileURL,fileURLToPath}from"node:url... 
        ╵                                                     ~~~~~

  The package "url" wasn't found on the file system but is built into node. Are you trying to bundle
  for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:379:
      1 │ ..."url";import"node:url";import"module";import"worker_threads";import"node:fs/promises";import"./pages/al... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/internal.84fa9326.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:url"

    dist/$server_build/chunks/astro.451db360.mjs:1:420:
      1 │ ...om"url";import{pathToFileURL,fileURLToPath}from"node:url";import{createRequire}from"module";import{Work... 
        ╵                                                   ~~~~~~~~~~

  The package "node:url" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:402:
      1 │ ...mport"module";import"worker_threads";import"node:fs/promises";import"./pages/all.e3f32280.mjs";getConfi... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "module"

    dist/$server_build/chunks/astro.451db360.mjs:1:456:
      1 │ ...LToPath}from"node:url";import{createRequire}from"module";import{Worker,parentPort}from"worker_threads";... 
        ╵                                                    ~~~~~~~~

  The package "module" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

X [ERROR] Could not resolve "worker_threads"

    dist/$server_build/chunks/astro.451db360.mjs:1:494:
      1 │ ...e}from"module";import{Worker,parentPort}from"worker_threads";import"node:fs/promises";const DELETED_EXP... 
        ╵                                                ~~~~~~~~~~~~~~~~

  The package "worker_threads" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

X [ERROR] Could not resolve "node:fs/promises"

    dist/$server_build/chunks/astro.451db360.mjs:1:517:
      1 │ ...rker,parentPort}from"worker_threads";import"node:fs/promises";const DELETED_EXPIRATION=new Date(0),DELE... 
        ╵                                               ~~~~~~~~~~~~~~~~~~

  The package "node:fs/promises" wasn't found on the file system but is built into node. Are you
  trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this
  error.

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/_worker.mjs:1:257:
      1 │ ...e";import"kleur/colors";import"slash";import"path-to-regexp";import"string-width";import"html-escaper";... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/stonewall.239832fe.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/met-office.9356ce08.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/internal.84fa9326.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/discord-guidelines.af1336f3.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/hike-leader-prompt.646c744c.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/os-maps.c0e05977.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/chunks/lgbt-foundation.43ecf60e.mjs:1:167:
      1 │ ..."./Image.4ea9674c.mjs";import"cookie";import"path-to-regexp";import"mime";import"kleur/colors";import"s... 
        ╵                                                ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

 error   Could not resolve "node:fs"
  File:
    dist/$server_build/_worker.mjs:1:322

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-5gayx2

Participation

matthewp commented 1 year ago

I'm pretty sure this is because we are using node: in the new experimental assets features. We need to avoid importing this if it is not used.

matthewp commented 1 year ago

Ah, never mind. The example does use the experimental assets. This feature doesn't yet work outside of Node.js. So you can't use it with the Cloudflare adapter.

matthewp commented 1 year ago

@Princesseuh is going to add a warning about using the service, and that's it's only available in Node.js. @Princesseuh personally I think just a simple warning on every dev / build startup that says "Experimental assets support is only available for Node.js runtimes", or something like that.

jackcarey commented 1 year ago

Ah, never mind. The example does use the experimental assets. This feature doesn't yet work outside of Node.js. So you can't use it with the Cloudflare adapter.

That would make sense, so I took out the experimental object from the astro config and unused references to the Image element. However, I get the same error 😕

jackcarey commented 1 year ago

@matthewp I'm still receiving the error even when the experimental assets aren't being used. My config now looks like this:

import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import critters from "astro-critters";
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
  site: 'https://astro-site.pages.dev/',
  integrations: [mdx(), tailwind(), sitemap(), critters(), compress()],
  output: "server",
  adapter: cloudflare({ mode: 'directory' }),
  // output: "static",
});
matthewp commented 1 year ago

@jackcarey yep, we found a place where that code was being mistakenly imported,when using content collections, and the fix will be released shortly.

jackcarey commented 1 year ago

@jackcarey yep, we found a place where that code was being mistakenly imported,when using content collections, and the fix will be released shortly.

The update for 6.2.1 fixed the issue - Thank you, I appreciate it :)

james2doyle commented 1 year ago

Consider trying out the new Compatibility flags: nodejs_compat to ensure Node imports work

Screen Shot 2023-05-19 at 4 01 09 PM

This worked for me. I am using Cloudflare Pages and the Cloudflare Adapter with hybrid output.

nikunjitaliya2 commented 1 year ago

not work above sol

mikob commented 1 year ago

@james2doyle 's solution doesn't work for me either. There are apparently libraries that the experimental assets use that are not handled by the nodejs_compat layer. However, this workaround works for limited use cases: https://github.com/withastro/astro/issues/4109#issuecomment-1653149464

jadbox commented 1 year ago

I'm still getting build errors:

node_modules/pg/lib/native/client.js:12:27:
  12 │ var EventEmitter = require('events').EventEmitter
pthurmond-vmlyr commented 11 months ago

I am seeing this same problem in Astro v3.2.3. I am using the AstroWind theme and I am seeing the error even on some plaintext pages for privacy and terms & conditions. Possibly because I am importing a picture for the logo from the Assets directory.

ColeTownsend commented 8 months ago

Still getting this in 3.5.3 using the cloudflare adapter.

vtisnado commented 7 months ago

@pthurmond-vmlyr

I am seeing this same problem in Astro v3.2.3. I am using the AstroWind theme and I am seeing the error even on some plaintext pages for privacy and terms & conditions. Possibly because I am importing a picture for the logo from the Assets directory.

Have you found any working solution? I'm using Astro v4.2.6 with Astrowind v1.0.0-beta.15 and still can't get it work with the Cloudflare adapter.

pthurmond-vmlyr commented 7 months ago

Ok, so I eventually got it working. I can't remember exactly what I ended up doing. But here is what I am seeing in my code from December.

package.json

dependencies: "@astrojs/cloudflare": "^7.7.1", "wrangler": "^3.16.0"

devDependencies: "miniflare": "^3.20231030.0",

astro.config.mjs

import cloudflare from "@astrojs/cloudflare";

// Updates to config output: 'hybrid', adapter: cloudflare()

I think the hybrid part was crucial.

pthurmond-vmlyr commented 7 months ago

I did upgrade to Astro 4 a few weeks ago. Below are the versions I now have for each package.

"@astrojs/cloudflare": "^9.0.0", "wrangler": "^3.16.0" "miniflare": "^3.20231030.0",

As you can see, I only needed to update the first package.

If you want I can post a full copy of my package.json.

vtisnado commented 7 months ago

Thanks for sharing @pthurmond-vmlyr I tried to manually install those libraries, but still getting the Could not resolve "fs" error. I suspect it could be necessary additional configuration in astro.config.mjs

pthurmond-vmlyr commented 7 months ago

Ok, I have added my config and my package.json to a Github Gist.

https://gist.github.com/pthurmond-vmlyr/bdbeebefbdebdabaae85a079f310031a

I can add more files to that if you need it.

pthurmond commented 3 months ago

FYI, I upgraded my site to the latest version of the Cloudflare adapter (v11.x) and my site no longer works with the Cloudflare adapter. This is being tested in a separate branch mind you. Local testing just requires using the npm run build command.

It does work with my previously stated version of the adapter (9.x).

"@astrojs/cloudflare": "^11.0.1", // Does not work

I don't yet have a solve for it, but I think the cloudflare adapter may need more work.

I do see a related ticket though.

pthurmond commented 3 months ago

I should add that the 10.x version also fails to work.

amirzezo201 commented 1 month ago

iam using 11.0.4 v but still same error "message": "No such module \"node:fs/promises\".\n imported from \"chunks/Layout_vA6ce0ss.mjs\"",