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

Prerendered server paths are not respected by latest version of Svelte Kit when used with Cloudflare adapter #9469

Closed
davej opened this issue Mar 21, 2023 · 2 comments

Comments

@davej
Copy link

davej commented Mar 21, 2023

Describe the bug

When I add export const prerender = true to +server.js then I expect the server will only be used during the prerender build step and Svelte will not try to set it up as dynamic server function on Cloudflare Pages. In my case this would fail because the prerender servers use nodejs APIs which are not available on the worker platform.

This worked in an earlier version of svelte (see repro) but is broken in the latest version.

Reproduction

To reproduce you can clone this repo: https://github.com/davej/svelte-prerender-repro

Then run the following commands:

pnpm i
pnpm build

❌ Build fails with [ERROR] Could not resolve "path/module/fs..." (see logs for full error)


But if I revert back to an older version of SvelteKit, using the following commands, it builds successfully.

pnpm i @sveltejs/kit@1.0.0-next.589
pnpm build

✅ Build passes

Logs

> Using @sveltejs/adapter-cloudflare
✘ [ERROR] Could not resolve "path"

    .svelte-kit/output/server/entries/endpoints/sitemap.xml/_server.js:1:17:
      1 │ import path from "path";~~~~~~

  The package "path" 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 "path"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:1:19:
      1 │ import __path from 'path';
        ╵                    ~~~~~~

  The package "path" 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 "url"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:2:49:
      2 │ import { fileURLToPath as __fileURLToPath } from '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.

✘ [ERROR] Could not resolve "module"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:3:49:
      3 │ import { createRequire as __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 "fs"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:21045:46:
      21045 │ import { readFileSync as readFileSync2 } from "fs";~~~~

  The package "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.

✘ [ERROR] Could not resolve "process"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:21057:21:
      21057 │ import process2 from "process";
            ╵                      ~~~~~~~~~

  The package "process" 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 "stream"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:21073:26:
      21073 │ import { Transform } from "stream";~~~~~~~~

  The package "stream" 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 "crypto"

    node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:21637:27:
      21637 │ import { createHash } from "crypto";
            ╵                            ~~~~~~~~

  The package "crypto" 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 during build:
Error: Build failed with 8 errors:
.svelte-kit/output/server/entries/endpoints/sitemap.xml/_server.js:1:17: ERROR: Could not resolve "path"
node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:1:19: ERROR: Could not resolve "path"
node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:2:49: ERROR: Could not resolve "url"
node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:3:49: ERROR: Could not resolve "module"
node_modules/.pnpm/@svelteness+kit-docs@1.1.2_svelte@3.57.0/node_modules/@svelteness/kit-docs/node/index.js:21045:46: ERROR: Could not resolve "fs"
...
    at failureErrorWithLog (/Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1604:15)
    at /Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1056:28
    at /Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1001:67
    at buildResponseToResult (/Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1054:7)
    at /Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:1166:14
    at responseCallbacks.<computed> (/Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:701:9)
    at handleIncomingPacket (/Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:756:9)
    at Socket.readFromStdout (/Users/davejeffery/code/test/svelte-prerender-repro/node_modules/.pnpm/esbuild@0.16.17/node_modules/esbuild/lib/main.js:677:7)
    at Socket.emit (node:events:537:28)
    at addChunk (node:internal/streams/readable:324:12)
 ELIFECYCLE  Command failed with exit code 1.

System Info

System:
    OS: macOS 13.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 68.36 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.4.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.12.1 - /usr/local/bin/npm
    pnpm: 7.26.3 - /Users/davejeffery/Library/pnpm/pnpm
  npmPackages:
    @sveltejs/adapter-cloudflare: ^2.2.0 => 2.2.0 
    @sveltejs/adapter-static: ^2.0.1 => 2.0.1 
    @sveltejs/kit: 1.13.0 => 1.13.0 
    svelte: ^3.57.0 => 3.57.0 
    vite: ^4.2.1 => 4.2.1 

Severity

blocking an upgrade

Additional Information

No response

@davej
Copy link
Author

davej commented Mar 21, 2023

It looks like this is a duplicate. There is an earlier issue here: #9463
I'll leave this open in case there's some extra context/info in my issue but please feel free to close this.

@dummdidumm
Copy link
Member

Closing as duplicate of #9463 - thanks for the additional reproduction, might be helpful.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants