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 on cloudflare #121

Open
Pasithea0 opened this issue Oct 9, 2024 · 13 comments
Open

Cannot build on cloudflare #121

Pasithea0 opened this issue Oct 9, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@Pasithea0
Copy link

I can't build on cloudflare pages. Using svelte adapter-auto it chooses cloudflare's adapter.
However, it does build with adapter-node but it just returns 404.
It works fine on vercel.

Here are the relevant logs:

Could not resolve "node:process"... Could not resolve "node:path"... Could not resolve "node:URL"... (Expand for log)
19:23:50.651 | > Using @sveltejs/adapter-auto
-- | --
19:23:50.935 | Installing @sveltejs/adapter-cloudflare...
19:23:51.514 | Progress: resolved 0, reused 1, downloaded 0, added 0
19:23:52.602 | Progress: resolved 325, reused 259, downloaded 6, added 0
19:23:52.605 | Packages: +6
19:23:52.609 | ++++++
19:23:52.754 | Progress: resolved 325, reused 260, downloaded 6, added 6, done
19:23:52.848 | .../[email protected]/node_modules/esbuild postinstall$ node install.js
19:23:52.949 | .../[email protected]/node_modules/esbuild postinstall: Done
19:23:53.251 |  
19:23:53.252 | devDependencies:
19:23:53.252 | + @sveltejs/adapter-cloudflare 3.0.2 (4.7.2 is available)
19:23:53.252 |  
19:23:53.254 | Done in 2.1s
19:23:53.340 | Successfully installed @sveltejs/adapter-cloudflare.
19:23:53.341 |  
19:23:53.341 | If you plan on staying on this deployment platform, consider replacing @sveltejs/adapter-auto with @sveltejs/adapter-cloudflare. This will give you faster and more robust installs, and more control over deployment configuration.
19:23:53.341 |  
19:23:54.019 | ✘ [ERROR] Could not resolve "node:process"
19:23:54.019 |  
19:23:54.019 | .svelte-kit/output/server/chunks/_page.js:2:20:
19:23:54.019 | 2 │ import minproc from "node:process";
19:23:54.019 | ╵                     ~~~~~~~~~~~~~~
19:23:54.019 |  
19:23:54.019 | The package "node: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.
19:23:54.019 |  
19:23:54.020 | ✘ [ERROR] Could not resolve "node:path"
19:23:54.020 |  
19:23:54.020 | .svelte-kit/output/server/chunks/_page.js:3:20:
19:23:54.020 | 3 │ import minpath from "node:path";
19:23:54.020 | ╵                     ~~~~~~~~~~~
19:23:54.020 |  
19:23:54.020 | The package "node: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.
19:23:54.020 |  
19:23:54.021 | ✘ [ERROR] Could not resolve "node:url"
19:23:54.021 |  
19:23:54.021 | .svelte-kit/output/server/chunks/_page.js:4:30:
19:23:54.021 | 4 │ import { fileURLToPath } from "node:url";
19:23:54.021 | ╵                               ~~~~~~~~~~
19:23:54.021 |  
19:23:54.021 | 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.
19:23:54.021 |  
19:23:54.147 | error during build:
19:23:54.148 | Error: Build failed with 3 errors:
19:23:54.148 | .svelte-kit/output/server/chunks/_page.js:2:20: ERROR: Could not resolve "node:process"
19:23:54.149 | .svelte-kit/output/server/chunks/_page.js:3:20: ERROR: Could not resolve "node:path"
19:23:54.149 | .svelte-kit/output/server/chunks/_page.js:4:30: ERROR: Could not resolve "node:url"
19:23:54.149 | at failureErrorWithLog (/opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1651:15)
19:23:54.149 | at /opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1059:25
19:23:54.150 | at /opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1004:52
19:23:54.150 | at buildResponseToResult (/opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1057:7)
19:23:54.150 | at /opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1086:16
19:23:54.150 | at responseCallbacks.<computed> (/opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:704:9)
19:23:54.150 | at handleIncomingPacket (/opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:764:9)
19:23:54.150 | at Socket.readFromStdout (/opt/buildhome/repo/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:680:7)
19:23:54.151 | at Socket.emit (node:events:514:28)
19:23:54.151 | at addChunk (node:internal/streams/readable:324:12)
19:23:54.219 | Failed: Error while executing user command. Exited with error code: 1
19:23:54.228 | Failed: build command exited with code: 1
19:23:55.291 | Failed: error occurred while running build command

These packages were not imported by me and it built fine after removing carta.

@itzCozi
Copy link

itzCozi commented Oct 9, 2024

Glad to see I wasn't the only one with this issue, we have been building it on railway instead sadly, Cloudflare pages is the best host though sad to see this package hinders it. When I build on Cloudflare using the cloudflare-adapter I get the same "Could not resolve" errors.

@BearToCode BearToCode added the bug Something isn't working label Oct 9, 2024
@BearToCode
Copy link
Owner

Hello,
I do not have experience using the cloudflare adapter. It seems like when bundling for the client some node packages are still included. I do not recognize any of the imports (minpath, minproc and fileURLToPath): they are probably importated from a dependency of the library. If you are able to determine which one is causing the issue, we might be able to tree-shake a wrongful import.

@Pasithea0
Copy link
Author

The issue is with carta. After removing carta package it builds. After adding carta, it fails to build. Everything else builds fine.

@BearToCode
Copy link
Owner

I mean that the issue is with a dependency of Carta, not of you project. It's hard to tell without seeing where the problematic imports are used.

@Pasithea0
Copy link
Author

Ah gotcha. The only reference to this issue I could find is here:

"Cloudflare has a different runtime than Nodejs so you won't have access to all of the node "things"."
https://www.reddit.com/r/sveltejs/comments/17u9p53/sveltekit_cloudflare_pages_node_core_modules/

I just hoped you had a workaround for this issue

@BearToCode
Copy link
Owner

Can you provide the .svelte-kit/output/server/chunks/_page.js file where the issue originates? I might be able to figure out what's causing the issue there.

@Pasithea0
Copy link
Author

_page.js.txt

@BearToCode
Copy link
Owner

Thanks to the file you provided I found the source of the import. It's carta-md -> unified -> vfile.

// vfile/lib/index.js
import {minpath} from '#minpath'
import {minproc} from '#minproc'
import {urlToPath, isUrl} from '#minurl'

(source)

Apparently, there should be a polyfill in place to replace the imports when node is not used. I don't know why it's not working and how it is implemanted.

@itzCozi
Copy link

itzCozi commented Oct 9, 2024

how can this be fixed?

@BearToCode
Copy link
Owner

I'd suggest trying to install vfile separately, using it for some basic task to prevent tree-shaking, and then building using the cloudflare-adapter, to determine whether the issue arises as well. You can then open a dedicated issue on the vfile repository.

I currently do not have the time to look into this myself, but I could implement a possible fix you come up with.

@Pasithea0
Copy link
Author

Well, I got it to work using the static adapter. Thanks for the help though!

@AyushSehrawat
Copy link

I'd suggest trying to install vfile separately, using it for some basic task to prevent tree-shaking, and then building using the cloudflare-adapter, to determine whether the issue arises as well. You can then open a dedicated issue on the vfile repository.

I currently do not have the time to look into this myself, but I could implement a possible fix you come up with.

Hi! Could you look into this if you got time?

> pnpm run build

.....logs

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

    .svelte-kit/output/server/chunks/_page.js:6:30:
      6 │ import { fileURLToPath } from "node:url";
        ╵                               ~~~~~~~~~~

  Cannot use "node:url" when deploying to Cloudflare.
.svelte-kit/output/server/chunks/_page.js:6:30

import { fileURLToPath } from "node:url";

^^^ this line is the problem

It's issue with VFIle class, like you mentioned.

On searching vfile repo, this issue vfile/vfile#81 comes up. That issue references another issue which is still open.

Any help would be appreciated!

Thanks

@BearToCode
Copy link
Owner

Hi, I'm quite busy at the moment and I don't have much time to look into this. Anyway, I tried to build using @sveltejs/adapter-cloudflare and no error showed up. I might have missed some configuration step. Could you provide a minimal reproducible example where that error shows up? I can't promise anything, but I'll try to check it out it as soon as I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants