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

[email protected] breaks deployment #13300

Open
vladjerca opened this issue Jan 12, 2025 · 7 comments
Open

[email protected] breaks deployment #13300

vladjerca opened this issue Jan 12, 2025 · 7 comments

Comments

@vladjerca
Copy link

vladjerca commented Jan 12, 2025

Describe the bug

After upgrading to @sveltejs/[email protected] deployments no longer work, the ./.svelte-kit/cloudflare now depends on ./.svelte-kit/output and cannot resolve external dependencies. (in my case @ts-rest/core).

Reproduction

Deployment using only ./.svelte-kit/cloudflare binaries: https://github.com/trakt/trakt-lite/actions/runs/12734910219/job/35493024100#step:5:68

Deployment with ./.svelte-kit/output unpacked: https://github.com/trakt/trakt-lite/actions/runs/12735478470/job/35494291485#step:6:68

Deployment with @sveltejs/[email protected] output: https://github.com/trakt/trakt-lite/actions/runs/12735605634/job/35494549765#step:5:67

Logs

No response

System Info

System:
    OS: macOS 15.1.1
    CPU: (14) arm64 Apple M3 Max
    Memory: 1.29 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
    bun: 1.1.30 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.1.1

Severity

blocking an upgrade

Additional Information

No response

@eltigerchino
Copy link
Member

eltigerchino commented Jan 13, 2025

As of [email protected], SvelteKit no longer uses esbuild to bundle the build. This is because Cloudflare's Wrangler also bundles the worker code when you try to deploy the project. We don't want to duplicate the bundling process so we let Cloudflare handle it instead (less error prone).

You should probably adjust your project's GitHub workflows to upload/download the entire ./svelte-kit directory instead of just ./svelte-kit/cloudflare so that Cloudflare can correctly bundle the files that the worker relies on that are outside the .svelte-kit/cloudflare directory. We can't copy the server files to that directory because they will be made public by Cloudflare Pages.

  1. https://github.com/trakt/trakt-lite/blob/05c0af44a38120a68626ea57d34c3859f3424705/.github/actions/upload-output/action.yml#L24
  2. https://github.com/trakt/trakt-lite/blob/05c0af44a38120a68626ea57d34c3859f3424705/.github/workflows/cd.yml#L27

@eltigerchino eltigerchino closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2025
@vladjerca
Copy link
Author

@eltigerchino I tried again including the entire build output (intially when I opened the issue I included only the output and cloudfare directories).

As you can see in this run: https://github.com/trakt/trakt-lite/actions/runs/12756619076/job/35555130981#step:5:72

Publishing these binaries result in cloudflare erroring on external dependencies, I've temporarily reverted the upgrade (again) trakt/trakt-lite#277.

@eltigerchino
Copy link
Member

@eltigerchino I tried again including the entire build output (intially when I opened the issue I included only the output and cloudfare directories).

As you can see in this run: trakt/trakt-lite/actions/runs/12756619076/job/35555130981#step:5:72

Publishing these binaries result in cloudflare erroring on external dependencies, I've temporarily reverted the upgrade (again) trakt/trakt-lite#277.

I forgot, you probably need to have your node_modules folder as well or else Wrangler won't be able to bundle the dependencies your code is referencing.

@vladjerca
Copy link
Author

@eltigerchino this sort of defeats the purpose of a deployment pipeline.

We build our artifacts and deploy later (could be arbitrary time later...).

From where I come from a build artifact is deployable at any point in time...

@vladjerca
Copy link
Author

So I've been thinking, I can understand you guys want to skip the build step (conceptually) but then I believe that the adapter should at a minimum:

  • copy node_modules packages referenced by the output

Also can we please re-open this issue @eltigerchino I don't see this as resolved 😕

@dil-zgaal
Copy link

I have the same issue.

I understand that some build task is now moved for wrangler, but in that case could wrangler provide a tool to bundle the build into a single package/dist folder, etc. ? A self contained artifact is quite essential for many pipelines where a (tested) artifact can be deployed any time (to any compatible environment).

gzp79 pushed a commit to gzp79/shine-web that referenced this issue Feb 2, 2025
@eltigerchino
Copy link
Member

eltigerchino commented Feb 3, 2025

It's possible to compile the _worker.js file through the wrangler deploy --dry-run CLI command, but it might be better if we had a Wrangler API to bundle the worker for us.
cc: @dario-piotrowicz @petebacondarwin @jamesopstad

As a workaround for now, you could install wrangler and modify your build script like below and it should work:

# bundles the worker to a temp directory then copies it over to .svelte-kit/cloudflare
vite build && wrangler deploy ./.svelte-kit/cloudflare/_worker.js --dry-run --outdir ./.svelte-kit/cloudflare-tmp --name worker --compatibility-date 2025-02-03 && cp ./.svelte-kit/cloudflare-tmp/_worker.js ./.svelte-kit/cloudflare/_worker.js

#13072 is related as that removes the custom bundle step too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants