Skip to content
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

Trouble getting source map to work #29

Closed
lewebsimple opened this issue Mar 9, 2018 · 16 comments
Closed

Trouble getting source map to work #29

lewebsimple opened this issue Mar 9, 2018 · 16 comments

Comments

@lewebsimple
Copy link

Maybe I'm missing something but I can't get the sourcemaps to generate either as a separate file or inline. I'm using the latest webpack (4.1.1) and mini-css-extract-plugin (0.2.0).

Relevant webpack module rules:

      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {sourceMap: true},
          },
        ]
      },

      {
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {sourceMap: true},
          },
          {
            loader: 'sass-loader',
            options: {sourceMap: true},
          },
        ]
      },

...and plugin:

    new MiniCssExtractPlugin({
      filename: 'css/styles.css'
    }),

Do I need to specify devtool property also ?

@lewebsimple
Copy link
Author

Nevermind, I figured it out... turns out you actually need devtool: 'source-map' after all!

@yantakus
Copy link

Why doesn't it work with devtool: 'cheap-module-eval-source-map'? Would be very useful to have this information in the readme.

@ruben-grossmann
Copy link

Good Question @yantakus !
I have the same problem with stylus instead of sass.
And i can't use devtool: 'source-map' because then the build takes way to much time.

I finally got it work with devtool: 'cheap-module-eval-source-map' and

plugins: [
    new SourceMapDevToolPlugin({
        filename: "[file].map",
        exclude: ["/vendor/"]
    })
]

They say you should not do that:

Never use both the devtool option and plugin together.
https://webpack.js.org/configuration/devtool/

But it works!

Now i have this:
sourcemap1

Instead of this:
sourcemap2

And the build still is fast.
Would be nice if someday it will work without this hack.

armaanahluwalia added a commit to armaanahluwalia/zulip that referenced this issue May 2, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
armaanahluwalia added a commit to armaanahluwalia/zulip that referenced this issue May 2, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
armaanahluwalia added a commit to armaanahluwalia/zulip that referenced this issue May 2, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
timabbott pushed a commit to zulip/zulip that referenced this issue May 3, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
@gkatsanos
Copy link

Could the maintainer of this plugin clarify whats happening here?

@andrastothtw
Copy link

andrastothtw commented May 4, 2018

I have an error when both css-loader and less-loader is set to sourceMap: true.

use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: { sourceMap: true },
          },
          {
            loader: 'less-loader',
            options: { sourceMap: true },
          },
        ],

The error message:

ERROR in ./src/styles/main.less
Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot read property 'context' of undefined
at Object. (/Users/andras.toth/IdeaProjects/contact-form-frontend/node_modules/css-loader/lib/loader.js:101:58)
at Array.map ()
at Object. (/Users/andras.toth/IdeaProjects/contact-form-frontend/node_modules/css-loader/lib/loader.js:99:31)`

I'm loading the file in our index.js file like this: require('./src/styles/main.less');

And of course no css.map file is generated.

@alexander-akait
Copy link
Member

@andrastothtw problem in css-loader, please look on stack before posting. Thanks!

@gkatsanos
Copy link

gkatsanos commented May 4, 2018

source-map doesn't work with HMR.

@heyalbert
Copy link

heyalbert commented May 12, 2018

Same configuration as lewebsimple but newer webpack version (4.8.1). Sourcemap doesn't work at all. Bug? How does your solution looks like?

shubham-padia pushed a commit to shubham-padia/zulip that referenced this issue May 27, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
brickbite pushed a commit to brickbite/zulip that referenced this issue May 29, 2018
This commit removes the flash on unstyled content while in dev
mode that was caused by the use of style-loader. Instead it
enables mini-css-extract-plugin in dev in combination with
css-hot-loader which enables HMR for development.

This is because mini-css-extract-plugin does not currently support
HMR out of the box. It also adds a SourceMapDevtoolPlugin to enable
sourcemaps with css since mini-css breaks sourcemaps when used in
combination with the cheap-module-evel-source-map setting.

Related issues:
webpack-contrib/mini-css-extract-plugin#34
webpack-contrib/mini-css-extract-plugin#29
@yamass
Copy link

yamass commented May 30, 2018

@lewebsimple Could you please reopen this issue? Using devtool: 'source-map' might be ok for production builds but not for development (much too slow). This needs to get fixed.

I personally use devtool: 'cheap-module-source-map' as a workaround, but it is still much slower than cheap-module-eval-source-map.

@Pushplaybang
Copy link

yeah seriously, this is confusing and frustrating as all hell.

@Younghun-Jung
Copy link

Have any solution?
CSS sourcemap is not working on webpack-dev-server in Webpack4 with MiniCssExtractPlugin...

@mwilkins91
Copy link

Same issue,


    new webpack.SourceMapDevToolPlugin({
      filename: '[name].[chunkhash:8].js.map',
      exclude: /vendors*(.+?).js/,
      lineToLine: true,
      columns: false,
    }),

results in no sourcemaps being generated for extracted css

@alexander-akait
Copy link
Member

Please don't spam difference issue in other issue, your problem can't be solved here never, source map getting from css-loader, so many features can't be supports due limitation loader api, we need implement out of box css support in webpack to solve many of them, thanks

@ivan-vilches
Copy link

Any solution?

@phxism
Copy link

phxism commented Jun 21, 2020

@ProTip
Copy link

ProTip commented Jul 11, 2020

@SirKlaus you saved my day by helping wrap up a final loose end!

I used include: [/\.css$/] to generate only CSS source map files but otherwise this solution works great so far.

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

No branches or pull requests