template icon indicating copy to clipboard operation
template copied to clipboard

Getting sourceMap warnning when run `npm run build`

Open code-doge opened this issue 5 years ago • 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,

code-doge avatar Sep 15 '20 06:09 code-doge

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 }),    

lucaspontoexe avatar Oct 09 '20 12:10 lucaspontoexe

So I must choose either a warning or a source map? There is no such choice like no warning and source map?

duongdominhchau avatar Mar 06 '21 09:03 duongdominhchau

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?

risingtiger avatar Mar 19 '21 01:03 risingtiger

Same here, how to disable that annoying warning?

frederikhors avatar Mar 24 '21 16:03 frederikhors

I think it disappear if you put sourcemap: false in rollup's output.

frederikhors avatar Mar 24 '21 16:03 frederikhors

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,
    }),
...

abcfy2 avatar Mar 25 '21 02:03 abcfy2

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.

sommerper avatar Apr 03 '21 13:04 sommerper

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.

greenchapter avatar Apr 29 '21 08:04 greenchapter

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
        }),
        // ...
    ],
    // ...
};

nilslindemann avatar Jan 11 '22 14:01 nilslindemann

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 :)

evdama avatar Apr 01 '22 07:04 evdama