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
[Sveltekit] Strange behaviour of Source Maps #8294
Comments
Hey, thanks for reporting this. Since the svelte-kit SDK (and the vite plugin) are still quite new we still have to figure out some stuff in regards to source maps. The difficulty lies in svelte-kit seemingly having multiple build steps and keeping source maps and source files aligned throughout these build steps is a bit tricky. I believe we're in communication with Vercel and Rich Harris about this. cc @Lms24 |
Sure, no worries 👍 It's not super-important to me, as the build output is actually quite readable and not too different from the source (at least for the |
Hey @hrueger 👋 just a few questions:
|
Hi, import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';
const checkOrigin = process.env.NODE_ENV !== "development";
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [
vitePreprocess(),
preprocess({
scss: {
prependData: '@use "src/variables.scss" as *;'
}
})
],
kit: {
adapter: adapter(),
alias: {
$myLib: '../_lib',
},
csrf: {
checkOrigin
}
}
};
export default config; So just the standard stuff, basically. I don't think it has something todo with the alias, since although FYI I'm using a monorepo with multiple packages, but when I'm building, I'm doing that from inside the folder of the respective package, so that shouldn't be a problem either. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Still an issue |
Hey, sorry for letting this slip through! I'll try to reproduce this so we can fix it. On first glance, it seems like the stack frame is rewritten incorrectly inside the SDK: Meanwhile, can you confirm that the error happens inside a |
Hi @Lms24 no worries.
Yes, this error happens in a |
Yes, this banner appears if source maps don't work and the stack trace is still bundled/minified. The message is very generic across all JS frameworks, so please ignore the Webpack/CLI part for now. |
@hrueger I tried reproducing this and so far I can't, meaning errors caught in server load functions or in server routes show up source-mapped for me. Please take a look at my repo (or feel free to fork it) and see where the configuration differs. You said you configured the I'm still sure that your server-side errors' stack frames are rewritten incorrectly but I can't yet figure out why. export default defineConfig({
plugins: [
sentrySvelteKit({
adapter: 'node'
}),
sveltekit(),
],
}); Btw: The "Sentry not part of build pipeline" warning is buggy indeed. It shows up for my test errors although they're correctly source-mapped. If you encounter this as well, please ignore it, I already raised it internally with the respective team. |
Hi @Lms24, I can't view the repository, maybe it's private?
Sure, I'll do next time I'm deploying (probably tomorrow). I wonder if it has to do with my monorepo setup. I have a couple of completely separate sveltekit apps in the - name: Build package
run: yarn build
working-directory: packages/${{ matrix.package }}
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: dein-ticket-shop
SENTRY_PROJECT: dts-${{ matrix.package }} |
Sorry perhaps I'm missing something obvious but all I can see is your
Whoops, sorry about that - I set it to public now
Hmm it's possible (monorepos always bring some challenges) but we usually look up things relative to |
but it shouldn't matter if you use it or not |
Sorry, I mixed that up. Here's the import { sveltekit } from '@sveltejs/kit/vite';
import { sentrySvelteKit } from "@sentry/sveltekit";
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sentrySvelteKit(), sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "src/variables.scss" as *;'
}
}
}
};
export default config; |
Unfortunately, setting the adapter manually does not help. Here's a new error from today, but I don't see any difference regarding source maps: https://dein-ticket-shop.sentry.io/issues/4314817573/?project=4505312392904704&query=is%3Aunresolved&referrer=issue-stream&stream_index=0 |
I had another thought. Can you describe a little what you're doing when deploying after building? The reason I'm asking is that our plugin tries to find the Also, did you try running the production build locally within the sveltekit project and throwing a test error? Would be interesting to see if source maps work then. So:
|
Sure. So after FROM node:18
RUN apt update && apt install tzdata -y
ENV TZ=Europe/Berlin
ENV BODY_SIZE_LIMIT=5242880
WORKDIR /app
COPY build .
COPY package.json .
COPY prisma .
ENV NODE_ENV production
RUN echo "nodeLinker: node-modules" > .yarnrc.yml && yarn set version berry && yarn plugin import workspace-tools && yarn workspaces focus --production && yarn setup
EXPOSE 3000
CMD npx prisma migrate deploy && node index.js basically, it just copies However, I just found what could be the problem: I'm manually modifying js files after the build process. Somehow, lots of js files contain the following: import 'string_decoder/';
import 'string_decoder'; That throws an error. It's hard to test, though, because I need to find and fix whats causing that trailing slash. |
I think this might be it. I just reproduced this in my reproduction app I posted above:
==> The error is not source mapped anymore. It makes sense because our SDK (wrongfully in this case) assumes that the output directory of the adapter remains untouched. We need try to detect this better when rewriting the stack frame filenames or (if not possible) provide an option to override the directory name. Meanwhile, you can probably fix this by modifying your import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter({
out: 'app' // <-- this will change the output directory from build to app. Our sentrySvelteKit plugin detects this automatically
})
}
}; and slightly adjusting your dockerfile:
I think a slight modification like this shouldn't cause too much harm but yes, changing JS after the build has potential to corrupt the source map linking. I'm not sure when or how the import is added but you might want to look into creating a custom vite plugin and using a tool like |
That makes sense, thanks for the hint. |
So we're one step further in this mystery, it seem 😅 I took a look at the uploaded source map of this issue and I can see that the
The SvelteKit team seems to be aware of both issues and they recently tried to fix 1 but had to revert due to some problems. Not sure if/when they're gonna attempt again. Anyway, we actually use Since I'm still unable to reproduce this, can you turn on the
I might have to ask you to add some console logs directly in your |
Hi, thanks for the next steps. I'll look into that on Sunday since I'm ooo till then. |
Hm, I stripped it down for you and suddenly it is working... very strange. I need to do that again and just remove bit by bit and see when it breaks. I'll keep you updated. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you remove the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/sveltekit
SDK Version
7.54.0
Framework Version
@sveltejs/kit@1.20.1
Link to Sentry event
https://dein-ticket-shop.sentry.io/issues/4231736390/?project=4505312390610944&referrer=project-issue-stream
SDK Setup
Steps to Reproduce
I just caught an error in my Sveltekit Project. However, the filepath is wrong:
However, source maps are uploaded and seem to be working partly?
Sentry was configured just as in the documentation, with the plugin in
vite.config.js
. No special settings / config, whatsoever.Expected Result
I see the correct filename in sentry.
Actual Result
Wrong filename (see above)
I also can't connect GitHub, which is currently not possible due to the wrong filename:
(obviously there are no built files in my GitHub Repo).
Thanks for your help!
The text was updated successfully, but these errors were encountered: