Getting sourceMap warnning when run `npm run build`
code-doge opened this issue ยท 10 comments
fresh project just cloned from repo, and ran typescript setup script.
Getting warning when run npm run build
:
Plugin typescript: @rollup/plugin-typescript: Typescript 'sourceMap' compiler option must be set to generate source maps.
checked that sourceMap is actually set to true in @tsconfig/svelte/tsconfig.json
/**
To have warnings/errors of the Svelte compiler at the correct position,
enable source maps by default.
*/
"sourceMap": true,
By default, Svelte doesn't generate source maps in production mode, which will get you this warning.
You can generate them by changing rollup.config.js
:
- typescript({ sourceMap: !production}),
+ typescript({ sourceMap: true }),
So I must choose either a warning or a source map? There is no such choice like no warning and source map?
I am interested in how to resolve this as well. Its great to have source maps with npm run dev. But, obviously having them on build isn't good. Is there a way to tweak svelte and/or typescript configurations to enable sourcemaps only on dev AND disable a warning on build?
Same here, how to disable that annoying warning?
I think it disappear if you put sourcemap: false in rollup's output.
I think it disappear if you put sourcemap: false in rollup's output.
Hi @frederikhors , but how to disable bundle.css.map
? sourceMap: false
in output
seems not working.
Here is my config:
...
export default {
preserveEntrySignatures: false,
input: ["src/main.ts"],
output: {
sourcemap: !production,
format: "esm",
dir: buildDir,
// for performance, disabling filename hashing in development
chunkFileNames: `[name]${(production && "-[hash]") || ""}.js`,
},
plugins: [
svelte({
dev: !production, // run-time checks
// Extract component CSS โ better performance
css: (css) => css.write(`bundle.css`),
hot: isNollup,
preprocess: sveltePreprocess({
sourceMap: !production,
postcss: true,
}),
}),
// resolve matching modules from current working directory
resolve({
browser: true,
dedupe: (importee) => !!importee.match(/svelte(\/|$)/),
}),
commonjs(),
typescript({
sourceMap: !production,
inlineSources: !production,
}),
...
I stumbled upon this thread because I had the same problem when first initializing a ts project.
It must have been a oversight that output.sourcemap = true
is not output.sourcemap = !production
But changing that line in rollup.config.js
seemed to do the trick for me.
When you build by running npm run build
with rollup the sourcemap
option will bet set to true
.
output: {sourcemap: true}
The right solution to remove the warning on prod build would be, to add a dependecy to the environment.
output: {sourcemap: !production}
That works for me.
Using Typescript, based on this SO answer, seemingly this config does the job. The magic key is enableSourcemap
:
// ...
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
// ...
const production = !process.env.ROLLUP_WATCH;
// ...
export default {
// ...
output: {
sourcemap: !production,
// ...
},
plugins: [
svelte({
preprocess: sveltePreprocess({
sourceMap: !production
}),
compilerOptions: {
dev: !production,
enableSourcemap: false // Set to true if you want them
}
}),
// ...
typescript({
sourceMap: !production,
inlineSources: !production
}),
// ...
],
// ...
};
Just to clarify, enableSourcemap: true
is actually the default as mentioned in the docs so no need to set it explicitly right? https://svelte.dev/docs#compile-time-svelte-compile
The actual reason I came here too is that I stumpled accross that SO thread first as well because I have a Sveltekit project with typescript and I'd like to enable debugging inside VSCode for serverside code (hooks.ts
) that runs on Node.js... but then as mentioned at this SO thread, I'm also getting Unbound Breakpoints which I think has to do with some missing config regarding ts files and sourcemaps... anyhow, not to deviate from this thread here... just my current understanding... of somewhat simillar subjects :)