Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Adapter unable to resolve node:fs #6529

Closed
1 task done
jackcarey opened this issue Mar 13, 2023 · 22 comments · Fixed by #6533
Closed
1 task done

Cloudflare Adapter unable to resolve node:fs #6529

jackcarey opened this issue Mar 13, 2023 · 22 comments · Fixed by #6533
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@jackcarey
Copy link

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

  • When disabling the CF adapter and switching to output: "static", the site builds and can be previewed, except I am obviously missing the Cloudflare functions I'm developing.
  • When running astro dev with the CF adapter and output: "server" the site builds and loads correctly in my browser.
  • When trying astro build --verbose, the build fails both locally and when pushing to CF Pages, with errors about built-in node modules that couldn't be found and warnings about packages being marked with sideEffects: false.
  • I've tried changing node versions and switching the adapter mode to advanced, to no avail.
  • I'm unable to reproduce the error in Stackblitz, as it just returns "Upgrade Required" with no errors in the console.
    -My repo is private for now, but I can make it public if necessary.

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

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Mar 13, 2023
@matthewp
Copy link
Contributor

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 matthewp added - P3: minor bug An edge case that only affects very specific usage (priority) and removed - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) labels Mar 13, 2023
@matthewp
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Author

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
Copy link
Author

@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
Copy link
Contributor

@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
Copy link
Author

@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
Copy link

james2doyle commented May 19, 2023

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
Copy link

not work above sol

@mikob
Copy link

mikob commented Aug 14, 2023

@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: #4109 (comment)

@jadbox
Copy link
Contributor

jadbox commented Oct 5, 2023

I'm still getting build errors:

node_modules/pg/lib/native/client.js:12:27:
  12 │ var EventEmitter = require('events').EventEmitter

@pthurmond-vmlyr
Copy link

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
Copy link

Still getting this in 3.5.3 using the cloudflare adapter.

@vtisnado
Copy link

@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
Copy link

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
Copy link

pthurmond-vmlyr commented Feb 15, 2024

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@amirzezo201
Copy link

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

@chaegumi
Copy link
Contributor

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

still same error

{
  "truncated": false,
  "executionModel": "stateless",
  "outcome": "exception",
  "scriptVersion": {
    "id": "7fac199a-66b2-4bb2-8ef4-e981f9ad8ceb"
  },
  "scriptName": "pages-worker--4049140-production",
  "diagnosticsChannelEvents": [],
  "exceptions": [
    {
      "name": "Error",
      "message": "No such module \"node:fs/promises\".\n  imported from \"pages/_---slug_.astro.mjs\"",
      "timestamp": 1729222872346
    }
  ],
  "logs": [
    {
      "message": [
        "03:41:12 [ERROR] Error: No such module \"node:fs/promises\".\n  imported from \"pages/_---slug_.astro.mjs\""
      ],
      "level": "error",
      "timestamp": 1729222872346
    }
  ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.