Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

Weird source map paths when used together with sass-loader #652

Closed

Description

@woldner

Do you want to request a feature or report a bug?
Bug report

What is the current behavior?
Wrong source map/resource paths using css-loader together with sass-loader as shown below:

Examples of source map paths using the plugin
The actual app.scss path is ./src/styles/app.scss

ex1

However the source map path for the file becomes ./src/styles/src/styles/app.scss and the absolute resource path: C:/Users/m51n/source/repos/source-map-path/src/styles/src/styles/app.scss (does not exist)

ex2

If the current behavior is a bug, please provide the steps to reproduce.
I've created a sample project here-- using the source map example from the sass-loader docs and code from the extract-text-webpack-plugin docs here

With the sample project above I used devtool: "inline-source-map".

What is the expected behavior?
Expected source map path returned by the plugin in this case would be ./src/styles/app.scss and absolute resource path as it exist on disk: C:/Users/m51n/source/repos/source-map-path/src/styles/app.scss

Related issues for reference
webpack/sass-loader#484

Please mention other relevant information such as your webpack version, Node.js version and Operating System.

webpack v3.10.0
node v9.2.0
os: windows 10

Activity

  1. dcatoday commented on Jan 3, 2018

    @dcatoday

    Hi I am seeing an issue using ~paths. The path is returned without any deliminating /'s in the url.

  2. Songworks commented on Jan 10, 2018

    @Songworks

    Came upon the same today with having duplicate-ish paths in sourcemaps.
    Here's the relevant loaders in my config (no ExtractTextPlugin and devtool as source-map):

      [
        {
          loader: 'style-loader',
        },
        {
          loader: 'css-loader',
          options: {
            sourceMap: true,
          },
        },
        {
          loader: 'sass-loader',
          options: {
            sourceMap: true,
          },
        },
      ];

    To me it seems like sass-loader uses the style file path relative to the current working directory and css-loader uses that same path as just a filename (rather than considering it a proper path?) and prepends the absolute path of the directory where the style file is imported from (regardless if it's by another style file or javascript)?

    As a quick example, two files:
    /cwd/src/styles/core.scss
    /cwd/src/components/bla/styles.scss

    Both will be imported by another file within /cwd/src/components/bla.

    Sourcemap for core.scss will have the path:
    /cwd/src/components/bla/src/styles/core.scss
    Sourcemap for styles.scss will have the path:
    /cwd/src/components/bla/src/components/bla/styles.scss

  3. woldner commented on Jan 10, 2018

    @woldner
    Author

    @Songworks see webpack/sass-loader#529
    @evilebottnawi promised that he would have a look in the near future 🔎

  4. alexander-akait commented on Jan 12, 2018

    @alexander-akait
    Member

    Just for information - reproducible test repo https://github.com/jwldnr/extract-text-issue

  5. mattmewton commented on Jan 19, 2018

    @mattmewton

    I'm having this issue as well. Any update as to when it will be resolved?

  6. woldner commented on Feb 12, 2018

    @woldner
    Author
  7. alexander-akait commented on Feb 12, 2018

    @alexander-akait
    Member

    @jwldnr sorry for delay, don't have time for this right now, PR welcome 👍

  8. alexander-akait commented on Feb 15, 2018

    @alexander-akait
    Member

    Feel free to PR if somebody have time

  9. woldner commented on Feb 15, 2018

    @woldner
    Author

    Understood 👍🏼

  10. vlad-ivanov-d commented on Apr 18, 2018

    @vlad-ivanov-d

    Hey guys, do you have any progress/plans on this issue?

  11. npetruzzelli commented on Apr 19, 2018

    @npetruzzelli

    I haven't been able to fix it, but I've done some digging and will share what I have found in hopes of it being useful to someone who has more time to put into it.

    In comment webpack/sass-loader#484 (comment)

    A deleted user claimed to have fixed the issue by editing what was line number 198 at the time:
    https://github.com/webpack-contrib/css-loader/blob/v0.28.4/lib/processCss.js#L198

    So all that was done was the prefix was removed.

    As of this writing, the line has changed to 204:
    https://github.com/webpack-contrib/css-loader/blob/v0.28.11/lib/processCss.js#L204

    /*202*/	pipeline.process(inputSource, {
    /*203*/		// we need a prefix to avoid path rewriting of PostCSS
    /*204*/		from: "/css-loader!" + options.from,
    /*205*/		to: options.to,
    /*206*/		map: options.sourceMap ? {
    /*207*/			prev: inputMap,
    /*208*/			sourcesContent: true,
    /*209*/			inline: false,
    /*210*/			annotation: false
    /*211*/		} : null
    /*212*/	}).then(function(result) {

    This code first appears in commit:
    09bd206

    as posted by @sokra to fix issue #154

    Before this commit, sources looked something like this:
    image

    This occured in version 0.19.x so the first release that saw this go into effect was 0.20.0:
    https://github.com/webpack-contrib/css-loader/blob/v0.20.0/lib/processCss.js#L167

    It looks like if the from attribute may need more work, then the rest of it may fall into place.

  12. 22 remaining items

  13. npetruzzelli commented on Nov 7, 2018

    @npetruzzelli

    Thanks @evilebottnawi - Since I haven't touched this since August, it will take me some time to get caught up / merge in changes that have come in since then. I will start with sass-loader per my prior comment. I may be a bit slow on the update as there is a lot going on personally and professionally right now, but I will try to have an update for you by the end of the month.

  14. alexander-akait commented on Nov 7, 2018

    @alexander-akait
    Member

    @npetruzzelli thanks for any helping 👍

  15. Nettsentrisk commented on Nov 8, 2018

    @Nettsentrisk

    extract-text-webpack-plugin is irrelevant for my case, since it's happening in develop mode with HMR, where style-loader and no extract plugins are being used (I use mini-css-extract-plugin anyway).

    I think this problem only affects Windows users, which might be why it's flown under the radar for so long.

  16. tenebrius commented on Nov 14, 2018

    @tenebrius

    Any progress or workaround guys?

  17. alexander-akait commented on Nov 14, 2018

    @alexander-akait
    Member

    @tenebrius Pr welcome

  18. npetruzzelli commented on Nov 28, 2018

    @npetruzzelli

    @evilebottnawi - A lot of the hectic stuff has passed. I plan to resume work on it shortly. I am sorry for the delay.

  19. alexander-akait commented on Nov 28, 2018

    @alexander-akait
    Member

    @npetruzzelli maybe i can help if you provide minimum reproducible test repo, i am already working on 2 version (you can look progress in master branch)

  20. npetruzzelli commented on Nov 30, 2018

    @npetruzzelli

    @evilebottnawi - I'll continue with comments in the PR: #753

    There, I've included a link to the fork and am in the process of merging in updates to the master branch. Once I have tests working, I will create a minimal, reproducible test repo (separate from the fork).

    Master still has version 1.x according to it's package.json file. If you intended for me to look at progress for 2.x in the next branch, I do not have permission to view that. I'm going to guess you want me to work from master, can you confirm that?

  21. alexander-akait commented on Nov 30, 2018

    @alexander-akait
    Member

    @npetruzzelli use master branch 👍

  22. Chris-Kim commented on Dec 19, 2018

    @Chris-Kim

    For me, this issue is resolved by upgrading css-loader to 2.x.x

  23. modified the milestones: 2.0.1, 2.1.1 on Mar 5, 2019
  24. alexander-akait commented on Mar 5, 2019

    @alexander-akait
    Member
  25. alexander-akait commented on Mar 6, 2019

    @alexander-akait
    Member

    Find solution and problem, will be solved and released today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions