Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Getting sourceMap warnning when run npm run build #174

Open
code-doge opened this issue Sep 15, 2020 · 10 comments · May be fixed by #241
Open

Getting sourceMap warnning when run npm run build #174

code-doge opened this issue Sep 15, 2020 · 10 comments · May be fixed by #241
Labels

Comments

@code-doge
Copy link

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,
@lucaspontoexe
Copy link

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

@duongdominhchau
Copy link

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

@risingtiger
Copy link

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?

@frederikhors
Copy link
Contributor

Same here, how to disable that annoying warning?

@frederikhors
Copy link
Contributor

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

@abcfy2
Copy link

abcfy2 commented Mar 25, 2021

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

@sommerper
Copy link

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.

@greenchapter
Copy link

greenchapter commented Apr 29, 2021

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 greenchapter linked a pull request Apr 29, 2021 that will close this issue
@nilslindemann
Copy link

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

@evdama
Copy link

evdama commented Apr 1, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.