-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
Weird source map paths when used together with sass-loader #652
Comments
Hi I am seeing an issue using ~paths. The path is returned without any deliminating /'s in the url. |
Came upon the same today with having duplicate-ish paths in sourcemaps. [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
]; To me it seems like As a quick example, two files: Both will be imported by another file within Sourcemap for core.scss will have the path: |
@Songworks see webpack-contrib/sass-loader#529 |
Just for information - reproducible test repo https://github.com/jwldnr/extract-text-issue |
I'm having this issue as well. Any update as to when it will be resolved? |
ping @evilebottnawi |
@jwldnr sorry for delay, don't have time for this right now, PR welcome 👍 |
Feel free to PR if somebody have time |
Understood 👍🏼 |
Hey guys, do you have any progress/plans on this issue? |
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-contrib/sass-loader#484 (comment) A deleted user claimed to have fixed the issue by editing what was line number 198 at the time: So all that was done was the prefix was removed. As of this writing, the line has changed to 204: /*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: as posted by @sokra to fix issue #154 Before this commit, sources looked something like this: This occured in version It looks like if the |
I'm not sure about what kind of file and folder structure @jhnns was originally running into that caused the screenshot he first posted but this is what I see if I remove the prefix, and it appears to be correct: Yes, my code is in a directory called const extractSass = new ExtractTextPlugin({
filename: "[name].css"
});
// ...
// ENTRY
entry: "./src-0/index.js",
// ...
// RULES
{
loader: "css-loader",
options: {
sourceMap: true
}
},
{
loader: "sass-loader",
options: {
sourceMap: true,
sourceMapContents: false
}
}
// ...
// PLUGINS
extractSass,
new SourceMapDevToolPlugin({
filename: "[file].map[query]",
moduleFilenameTemplate: "[resource-path]",
fallbackModuleFilenameTemplate: "[resource-path]?[hash]",
sourceRoot: "/",
noSources: true
}) Setting I could open a PR, but all I would be doing is: - // we need a prefix to avoid path rewriting of PostCSS
- from: "/css-loader!" + options.from,
+ from: options.from, I'm going to guess it needs to be looked into a bit deeper than that. |
I've been doing some additional digging, and it looks like the problem may be spread out between sass-loader, postcss-loader, and css-loader. css-loader, might still be contributing to it, but not as much as initially thought. I won't know until I can fix it locally and open up pull requests for each repository. |
@npetruzzelli |
@evilebottnawi I must respectfully disagree. As I will outline below, both postcss-loader and sass-loader alter the contents of the source map fields, so we can't say it "just outputs" (or otherwise passes through) anything. I'm still looking, but so far the only place I've found css-loader to be interacting with source maps is the following: Lines 118 to 130 in 8897d44
It looks like it is trying to repair fields that have incorrectly been assigned file system paths instead of URLs. It is doing more than that, but I haven't quite figured it out yet, though I think it may be connected to something the style-loader does. The postcss-loader does change maps. Specifically it changes both sourceRoot and sources from URLs to file system paths. While they have similar syntax (especially if you only consider relative paths) they are not the same thing. See: https://github.com/postcss/postcss-loader/blob/44167910d13fea32208989ffb31406f9577baf28/lib/index.js#L155-L157 sass-loader does the same: https://github.com/webpack-contrib/sass-loader/blob/2529c0716b1bca321c22d16636b1385682b1c730/lib/loader.js#L85-L94 node-sass is not responsible for the source maps, as it simply consumes LibSass. I've gone as far as to confirm that the comment in the code is incorrect with the LibSass project: sass/libsass#2651 The loader, at the very least, has access to the destination I am paying special attention to a note in node-sass's documentation: https://github.com/sass/node-sass/blob/8040cb7a0ab72a7c34120cc05be9e3e518f9ba34/README.md
If you'd like to reference the Source Map specification to confirm that the fields mentioned are not file system paths, you can find that here: Source Map Revision 3 Proposal Is there something I am missing that would invalidate any of the above? I will be happy to acknowledge I'm wrong if I'm wrong, so please help me understand it. I'm more interested in progress than being right. Kind regards. |
I met this issue too, and did some more investigation. Hopefully that can help. First, things I've read from the doc
In fact, I've identified one function in source-map util.join that is not compatible at all with absolute Windows path.
For example
Because they don't add the leading From what I've seen from the loaders on Windows:
|
PR welcome!
PR welcome!
It is require for internal works, we can fix it in next major release. |
I am experiencing the same thing! friendly ping to @jwldnr and @evilebottnawi I am using Windows and Wamp server, and all the things and options tried in Using, for example, "[absolute-resource-path]" returns this: http://mywebsite.how/assets/C:/wamp64/www/mywebsite/resources/assets/css/css/sass/resources/assets/css/css/sass/tablet/_footer.scss (part in bold is a weird duplicated part returned) what should return: My infos:1 - We are trying to automate the work, so we are trying to edit the file via Chrome Sources in DevTool mix.sourceMaps().webpackConfig({
devtool: 'source-map',
output: {
devtoolModuleFilenameTemplate: "file:///[ANY-OPTION]",
devtoolFallbackModuleFilenameTemplate: "file:///[ANY-OPTION]?[hash]"
}
}); I think solving this problem will help a lot of people. |
I'm experiencing the same problem on MacOS, the path to the original file on the source map is But the respective file is really at Note that there is a repeated |
I have found that removing the following line in node_modules/css-loader/lib/loader.js (line number 28 in css-loader version 1.0.0) fixes the problem for me:
|
Still not resolved? Any work-arounds? I'm having this problem with css-loader + postcss-loader + sass-loader. |
I'm still having the same issue. With my limited knowledge of these loaders it is hard to tell whether it is a problem at all. Will it break sourcemap support? Won't debugging work correctly? My debug points seem to be hit correctly. |
Please create minimum reproducible test repo |
|
@jwldnr don't use |
@evilebottnawi Here is a MWE: https://github.com/magnusriga/css-loader If you take a look at the source map paths in bundle.js within /dist, you will see the issue. The paths are wrong (multiple repeated /src paths, etc.). If you remove sass-loader from the loader chain, the problem disappears, for some reason. |
@jwldnr - to further support evil's comment, you can find additional documentation on the The extract text plugin calls this out:
More can be read in webpack-contrib/extract-text-webpack-plugin#749 @magnusriga - I have a PR open to work with evil on the issue, but he has other priorities he needs to work on before he can give my PR the time it needs for feedback. Please follow #753 and its counter part webpack-contrib/sass-loader#602 if you are interested, but be aware it will take some time before further action can be taken. |
@npetruzzelli |
@npetruzzelli Ok, thanks. Just as a heads up, my minimum working example does not include any extract loaders or plugins not needed to demonstrate the issue. It should be directly to the point. Quick question though: Will these paths cause any actual issues? i.e. won't source maps work properly? Thank you |
We are working on linux and source maps for |
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 |
@npetruzzelli thanks for any helping 👍 |
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. |
Any progress or workaround guys? |
@tenebrius Pr welcome |
@evilebottnawi - A lot of the hectic stuff has passed. I plan to resume work on it shortly. I am sorry for the delay. |
@npetruzzelli maybe i can help if you provide minimum reproducible test repo, i am already working on |
@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 |
@npetruzzelli use master branch 👍 |
For me, this issue is resolved by upgrading |
Other example https://github.com/kyle-ssg/sass-loader-bug |
Find solution and problem, will be solved and released today |
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 withsass-loader
as shown below:Examples of source map paths using the plugin
The actual
app.scss
path is./src/styles/app.scss
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)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 theextract-text-webpack-plugin
docs hereWith 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-contrib/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
The text was updated successfully, but these errors were encountered: