-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 worker build is resolving client-side files from libraries #12813
Comments
Hi Lukas, thanks for filing this issue. I'm not too knowledgeable on this but I tried adding ✘ [ERROR] No matching export in "node_modules/@sentry/sveltekit/build/esm/index.client.js" for import "sentryHandle"
.svelte-kit/output/server/chunks/hooks.server.js:10:9:
10 │ import { sentryHandle, handleErrorWithSentry } from "@sentry/svelt...
╵ ~~~~~~~~~~~~
error during build:
Error: Bundling with esbuild failed with 1 error
at adapt (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/@sveltejs/adapter-cloudflare/index.js:140:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async adapt (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/@sveltejs/kit/src/core/adapt/index.js:38:2)
at async finalise (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/@sveltejs/kit/src/exports/vite/index.js:891:7)
at async Object.handler (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/@sveltejs/kit/src/exports/vite/index.js:921:5)
at async PluginDriver.hookParallel (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/rollup/dist/es/shared/node-entry.js:20652:17)
at async Object.close (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/rollup/dist/es/shared/node-entry.js:21627:13)
at async build (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/vite/dist/node/chunks/dep-Cyk9bIUq.js:65455:17)
at async CAC.<anonymous> (file:///home/chewteeming/github/sentry-sveltekit-cloudflare-error/node_modules/vite/dist/node/cli.js:828:5)
ELIFECYCLE Command failed with exit code 1. Could you try adding the - const external = ['cloudflare:*', ...compatible_node_modules.map((id) => `node:${id}`)];
+ const external = ['cloudflare:*', ...compatible_node_modules.map((id) => `node:${id}`), '$app/*']; Not sure if this is the right thing to do, but to my understanding those $app imports are virtual modules and don't need to bundled in anyway (unless I'm mistaken here). Also, I'm curious if we need to add this to other adapters or if it's just cloudflare |
I tried both, setting
Which makes sense because I think the core issue still is that the esbuild build takes the wrong entry point for some reason. For reference, here are the relevant parts of my {
"main": "build/cjs/index.server.js",
"module": "build/esm/index.server.js",
"browser": "build/esm/index.client.js",
"worker": "build/cjs/index.server.js",
"types": "build/types/index.types.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./build/types/index.types.d.ts",
"browser": {
"import": "./build/esm/index.client.js",
"require": "./build/cjs/index.client.js"
},
"worker": {
"import": "./build/esm/index.server.js",
"require": "./build/cjs/index.server.js"
},
"node": "./build/cjs/index.server.js"
}
}
} As you can see, the only entries pointing to a client-side entry points are the I'd like to understand what the cloudflare adapter is doing with this esbuild command. Do you know what exactly it is building? I thought it's building a worker script but it doesn't really make sense to me why it'd take browser-side code for that. Maybe my understanding of the adapter is incorrect. |
To my understanding, it's bundling all the code and dependencies for the single worker that will be deployed. It uses the same |
Sorry for the naive question but the single worker basically is the server-side part of a regular sveltekit build, correct? |
Yes, that's right. |
Given Svelte 5 is released, any chance for an update on this? Unfortunately this is still a blocker for us and all SvelteKit<>Cloudflare<>Sentry users. |
Hi @Lms24 I tried re-arranging the exports order for "exports": {
"./package.json": "./package.json",
".": {
"types": "./build/types/index.types.d.ts",
"worker": {
"import": "./build/esm/index.server.js",
"require": "./build/cjs/index.server.js"
},
"node": "./build/cjs/index.server.js",
"browser": {
"import": "./build/esm/index.client.js",
"require": "./build/cjs/index.client.js"
}
}
}, Unfortunately this produces 74 other build errors related to node module imports that can't be used in the workerd runtime. As an aside, do you have a discord ID so that we can communicate directly? |
Hi, are there any more updates on this? Also, I'm wondering whether sveltekit could re-use more of the Cloudflare Wrangler esbuild config to solve this. For example, this plugin, that handles the It seems like that might then solve the node module import errors that you are referring to @eltigerchino , and then the re-arranged export order will work. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Needed together with changes to the Sveltekit Cloudflare Pages adapter, for sveltejs/kit#12813
I tried your suggested exports change @eltigerchino and got to the same 74 build errors, basically all variations of
Which I think is true for a native worker environment but if users enable
which they have to do anyway to use our CF SDK, these errors should be gone 🤔 However, it looks like this flag isn't respected by the build. I see #13132 attempts to fix this so I'm looking forward to seeing how this works :) |
We're still bundling in the Cloudflare workers adapter until #13072 is merged. Maybe we can separate that and the Workers Static Assets change into different PRs. |
Sure. I'll leave it to you guys. Whatever you prefer |
Describe the bug
When using our package
@sentry/sveltekit
in a minimal SvelteKit app with@sveltejs/adapter-cloudflare
, a build error is logged when the adapter is invoked (see logs).Upon closer inspection, it seems like the esbuild build within the cloudflare adapter is resolving the
browser
entry of our package'spackage.json
exports
instead of the server-side part. In the client-side part of our SDK package, weimport { page, navigating } from "$app/stores"
which esbuild can't resolve and therefore throws an error.I already tried adding a
worker
exports condition in our package.json that would point to server files but this doesn't do anything. It still seems like esbuild is accessing ourbowser
exports entry point.Reproduction
I created a minimal reproduction - please feel free to clone it
Logs
System Info
Severity
annoyance
Additional Information
⬆️ RE Severity: Blocker for users who'd like to add Sentry to their SvelteKit app running on Cloudflare
I'd appreciate any pointers as to what we/library authors need to do to support a use case where
$app/stores
Thanks a lot and please let me know if I can provide more information!
The text was updated successfully, but these errors were encountered: