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

Cannot build SSR with CloudFlare adapter and MDX #6535

Closed
1 task
carlosesquivelroisenvit opened this issue Mar 13, 2023 · 4 comments
Closed
1 task

Cannot build SSR with CloudFlare adapter and MDX #6535

carlosesquivelroisenvit opened this issue Mar 13, 2023 · 4 comments
Assignees
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Comments

@carlosesquivelroisenvit

What version of astro are you using?

2.1.2

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

Cloudflare

What package manager are you using?

npm

What operating system are you using?

Windows

What browser are you using?

Edge

Describe the Bug

The project fails to build if using the Cloudflare server adapter and having MDX or MD files in the /src/content folder. The astro dev command works correctly but astro build fails with the message below. Switching to Netlify adapter, for example, removes the error and builds successfully.

I have build a simple reproduction, cloning the Blogs sample and the error persists.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/_worker.mjs:9:7:
      9 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/_worker.mjs:10:7:
      10 │ import 'node:fs/promises';
         ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/_worker.mjs:11:7:
      11 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/astro.7e19134f.mjs:7:30:
      7 │ import { createRequire } from 'module';
        ╵                               ~~~~~~~~

  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.

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

    dist/$server_build/chunks/astro.7e19134f.mjs:8:7:
      8 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/astro.7e19134f.mjs:9:7:
      9 │ import 'node:url';
        ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/using-mdx.2ec409f4.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.2ec409f4.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/using-mdx.f994ec16.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.f994ec16.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.f994ec16.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.2ec409f4.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/first-post.44128e2e.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/first-post.44128e2e.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/first-post.44128e2e.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/markdown-style-guide.1f4ea981.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/markdown-style-guide.1f4ea981.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/markdown-style-guide.1f4ea981.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/second-post.990d068d.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/second-post.990d068d.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/second-post.990d068d.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/third-post.3f680662.mjs:8:7:
      8 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/third-post.3f680662.mjs:9:7:
      9 │ import 'node:fs/promises';
        ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/third-post.3f680662.mjs:10:7:
      10 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

✘ [ERROR] Could not resolve "module"

    dist/$server_build/chunks/using-mdx.2ba2f6cd.mjs:9:7:
      9 │ import 'module';
        ╵        ~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.2ba2f6cd.mjs:10:7:
      10 │ import 'node:fs/promises';
         ╵        ~~~~~~~~~~~~~~~~~~

  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.

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

    dist/$server_build/chunks/using-mdx.2ba2f6cd.mjs:11:7:
      11 │ import 'node:url';
         ╵        ~~~~~~~~~~

  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.

▲ [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:7:7:
      7 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/using-mdx.2ec409f4.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/using-mdx.f994ec16.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/first-post.44128e2e.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/markdown-style-guide.1f4ea981.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/second-post.990d068d.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/third-post.3f680662.mjs:3:7:
      3 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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/using-mdx.2ba2f6cd.mjs:4:7:
      4 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "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 "module"
  File:
    dist/$server_build/_worker.mjs:9:7
  Code:
    8 | import 'string-width';
    > 9 | import 'module';
         |       ^
      10 | import 'node:fs/promises';
      11 | import 'node:url';
      12 | import 'html-escaper';

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-tlztcd

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp self-assigned this Mar 13, 2023
@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 have a reduced example: https://stackblitz.com/edit/withastro-astro-w1bj5x?file=src%2Fpages%2Fblog%2F[...slug].astro . MDX is not necessary to recreate, just using cloudflare and content collections.

@carlosesquivelroisenvit
Copy link
Author

Thanks @matthewp will try to deploy without content collections for now and wait for the fix!

@matthewp
Copy link
Contributor

Fixed by #6537, will be released shortly.

@nadar
Copy link

nadar commented Nov 20, 2023

@matthewp @carlosesquivelroisenvit we use the latest version of astro (3.5.5) and we have the same problem :-/ Switched from Netlify to Cloudflare and we are unable to build the project anymore.

deps:

"dependencies": {
    "@astrojs/check": "^0.3.1",
    "@astrojs/cloudflare": "^7.7.1",
    "@astrojs/node": "^6.0.4",
    "@astrojs/tailwind": "^5.0.2",
    "@flyo/nitro-astro": "^1.0.4",
    "astro": "^3.5.5",
    "autoprefixer": "^10.4.16",
    "cssnano": "^6.0.1",
    "glider-js": "^1.7.8",
    "sass": "^1.69.5",
    "tailwindcss": "^3.3.5",
    "typescript": "^5.2.2"
  }

Errors:

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

    node_modules/import-meta-resolve/lib/get-format.js:5:33:
      5 │ import {URL, fileURLToPath} from 'node:url'
        ╵                                  ~~~~~~~~~~

  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.

 error   Could not resolve "node:fs"
  File:
    dist/$server_build/chunks/pages/__1b516472.mjs:5:15
  Code:
    4 | import path from 'node:path';
    > 5 | import fs from 'node:fs';
        |               ^
      6 | import { fileURLToPath } from 'node:url';
      7 | import { createShikiHighlighter } from '@astrojs/markdown-remark';
      8 | /* empty css                            */import camelcase from 'camelcase';
  Stacktrace:
Error: Build failed with 14 errors:

Astro.config

import { loadEnv } from "vite";
import { defineConfig } from "astro/config";
import flyoNitroIntegration from "@flyo/nitro-astro";
import tailwind from "@astrojs/tailwind";
import cloudflare from "@astrojs/cloudflare";
const {
  FLYO_ACCESS_TOKEN,
  FLYO_LIVE_EDIT
} = loadEnv(process.env.NODE_ENV, process.cwd() + "/src/", "");


// https://astro.build/config
export default defineConfig({
  site: "https://foobar.com",
  compressHTML: true,
  output: "server",
  integrations: [
    flyoNitroIntegration({
....
    }), 
    tailwind()
  ],
  adapter: cloudflare()
}); 

any idea how to fix that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)
Projects
None yet
Development

No branches or pull requests

3 participants