-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
npm package @sentry/sveltekit cannot be bundled by rollup #16190
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
Comments
I was able to resolve the issue with some workaround with "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-json": "^6.1.0", "@babel/preset-typescript": "^7.27.1", @rollup/plugin-node-resolve cannot resolve the @sentry/sveltekit for the node&cjs target function defaultRollupOptions() {
return {
external: requiredExternal,
output: {
// inlineDynamicImports: true,
format: 'cjs',
sourcemap: true
},
plugins: [
sourcemaps(),
nodeResolve({
preferBuiltins: true,
browser: false
}),
commonjs({
strictRequires: true
}),
json()
]
};
} for the plugin-alias I added this code {
find: '@sentry/sveltekit',
replacement: join(
process.cwd(),
'node_modules',
'@sentry',
'sveltekit',
'build',
'esm',
'index.server.js'
)
} This lead to issues with @opentelemetry package and @babel/preset-typescript (very strange) - cause it could not be found and bundled. So installing @babel/preset-typescript into adapter as a dependency helped. Somehow I was not able to externalize it. When sveltekit builds the app it seems it also cannot resolve it for the server part, suppose same issue with plugin-node-resolve. But it does not complain about it. Although I resolved the issue, it would be nice if it was fixed in @sentry/sveltekit. For the ref here is the app with adapter Thank you! |
Hi, thanks for letting us know about this! At this time, I'm not 100% sure this is an SDK problem but rather that you're trying to transpile a sveltekit app to CJS which as far as I can tell no longer is done by the official adapters. My guess is that the Also please note that you should not bundle the server side Sentry SvelteKit SDK. It has code in there that doesn't work when being bundled. Hence, we clearly instruct users to install the SDK as a dependency and not a dev dependency (svelteKit bundles devDependencies but not dependencies). I will leave this open for now (also taking a look at #16189) but can't promise that we'll change anything. |
@Lms24 Thank you for the info about bundling behaviour of the SK on the SSR, I didn't know that. But I also found info, that adapter-netlify bundles SSR dependencies I tried externalizing @sentry/sveltekit and instead adding it to the package.json and calling "npm install" before deploying to Azure Static Web apps. In this case the azure SWA managed function fails to start at all (but works locally with SWA). Unfortunately I could not find a way to get the startup error of the function app behind SWA as this seems to be an issue with Azure. I tried this with transpiling to CJS or using ES as output for rollup, but nothing worked as soon as @sentry/sveltekit is not bundled. I have not yet covered the code, that would not work when bundled, but I'm bundling at the moment, to get at least some functionality of sentry working. When I debug in SWA-CLI (sentry external) and debug into the module, even if I'm using ES output, it jumps to CJS code. I wonder, why it's working at all, cause SWA-CLI runs ES module worker. So maybe there are issues with resolutions in cloud SWA, and it fails with 'require' statement somewhere on the way. So at the moment I'm doing bundling with the following setup, adapter bundling (output in ES): const ignoreWarnCodes = new Set(['THIS_IS_UNDEFINED', 'CIRCULAR_DEPENDENCY']);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _adapterNode = adapterNode();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _adapterSWA = adapterSWA({
// external: ['@sentry/sveltekit'],
external: ['@babel/preset-typescript/package.json'],
apiDir: './func',
alias: {
'@sentry/sveltekit': join(
process.cwd(),
'node_modules/@sentry/sveltekit/build/esm/index.server.js'
)
},
onwarn: (warning, handler) => {
if (
ignoreWarnCodes.has(warning.code) ||
(warning.plugin === 'sourcemaps' && warning.code === 'PLUGIN_WARNING')
) {
// Ignore this warning
return;
}
// Use default warning handler for all other warnings
handler(warning);
},
... |
So I got it working as an external dep, the issue was with cloud version of azure static web apps - it behaves differently as the local swa-cli. Will document here if something is having issues. For the older version of adapter, it was transpiling to CJS, and using the package.json: {
"main": "**/index.js",
"dependencies": {
"@azure/functions": "^4",
}
} Now I have this one: {
"type": "module",
"main": "*/index.js", <== this line, swa-cli can handle "**/index.js" for type module, azure cloud cannot, so single "*" no recursion
"module": "*/index.js", <== this is ignored in both swa-cli and azure cloud 🤷♂️, but type is module....
"dependencies": {
"@azure/functions": "^4",
"@sentry/sveltekit": "^9.15.0"
}
} With this, this issue can also be closed. One comment though: the bundle size is enormous -> 160MB. A lot of things that probably should be in dev only 8.0K ./func/HelloWorld
4.0K ./func/host.json
4.0K ./func/local.settings.json
158M ./func/node_modules <== @azure/functions (if installed alone, 2.5MB) + sentry (installed alone) 157MB
124K ./func/package-lock.json
4.0K ./func/package.json
1.7M ./func/sk_render <== generated bundle without @sentry |
Thanks a lot for investigating this! I wanna follow up on it and check what we can do to simplify but realistically, this adapter is rather low on our list of priorities (sorry, just trying to be transparent).
This is for the server-side, though, right? We don't want to ship 160MB to the browser 🤞 |
Hi, Lukas! I think this one can be closed then. I would appreciate if you could suggest on how to handle rel-path resolution in the other issue. But this one is resolved for me. Thnaks for the support! |
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
"version": "9.15.0",
Framework Version
sveltekit "version": "2.20.8",
Link to Sentry event
N/A
Reproduction Example/SDK Setup
Warning I become: [plugin node-resolve] Could not resolve import "@sentry/sveltekit"
It also seems to me that the adapter-node also does not bundle it and leaves 'import "@sentry/sveltekit" as is, which means for azure swa this must be accompanied by according package.json (not good).
Could you please take a look and maybe provide just a simple ES npm?
Thnak you,
Konstantin
Steps to Reproduce
clone this branch https://github.com/kt-npm-modules/svelte-adapter-azure-swa/tree/feat/sentry
compare results of
npm run build
(adapter-node) andnpm run build:swa
(@ktarmyshov/svelte-adapter-azure-swa)Expected Result
Sveltekit, adapter-node and other using
rollup
should be able to bundle @setnry/sveltekit I suppose.Actual Result
@sentry/sveltekit is not bundled by rollup and left as external dep.
The text was updated successfully, but these errors were encountered: