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

sourcemap collision when building as a library #5767

Closed
MagicDuck opened this issue Oct 6, 2017 · 15 comments
Closed

sourcemap collision when building as a library #5767

MagicDuck opened this issue Oct 6, 2017 · 15 comments

Comments

@MagicDuck
Copy link
Contributor

MagicDuck commented Oct 6, 2017

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

What is the current behavior?
This happens when you have multiple webpack builds that integrate at runtime. For instance, I have a couple of projects that are built as webpack libraries (libraryTarget: "jsonp"). I use those libraries in a 3rd project. When I try to debug, I can see the sourcemaps for the libraries code in the devtool, but if you happen to have a file with the the same path in both libraries, for example:
"webpack:///src/index.js"
Then you basically just see the one for last loaded library...

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?
We should have a way namespace those paths. Would be nice if you could change only the webpack:/// prefix independent on the devtool being used. Then we could switch it to something like: webpack (<library name>):///
I am guessing there should be some config option, a function, which is applied on the template as a last thing before usage. The reason for not using output.devtoolModuleFilenameTemplate is that there seem to be different defaults for different devtool settings...
If this is a feature request, what is motivation or use case for changing the behavior?
debugging webpack built lilbraries
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

@sokra
Copy link
Member

sokra commented Oct 11, 2017

Are you thinking about adding the output.library name to the devtool prefix by default? This makes sense to me, so send a PR.

@MagicDuck
Copy link
Contributor Author

@sokra yes, will try to do that. I do have some questions though:

  1. In my case, the library name is too convoluted since we have designed a "plugin loading" mechanism,
    where each plugin is a webpack lib. The library name is something like mynamespace['my.plugin.with.dots']. I would like to able to modify the devtool prefix with a function before usage. EvalDevToolModuleTemplatePlugin, EvalSourceMapDevToolModuleTemplatePlugin and SourceMapDevToolPlugin seem to have their own defaults that get overriden though WebpackOptionsApply. Is it ok to add the option of output.devtoolModuleFilenameTemplate being a function (function(defaultTemplate : string) -> string), in which case it gets applied late, after the defaults have been set, rather than early? Or what would you consider to be the best way to approach this?
  2. What do you think the the base default be? Something like this: webpack:///([library])/[resourcePath]. This would also affect the current non-library case. We could make library="main" or something in that case so you would get webpack:///(main)/[resourcePath]. Would that be ok though? Or should we just change [resourcePath] to include the library name? I am not sure if that could break other stuff...
  3. What do we do about css-loader? It doesn't seem to respect the output.devtoolModuleFilenameTemplate. When I look at my ".css files" under webpack://, they all contain the js produced by the style-loader, it's not the original css. I don't think this is useful for the regular dev.

@sokra
Copy link
Member

sokra commented Oct 12, 2017

  1. We could add a options output.devtoolNamespace which defaults to the output.library when not specified. This way you can override it when a custom name is needed. Although __mynamespace__['my.plugin.with.dots'] will probably work too.
  2. For the non-library build devtoolNamespace should be undefined, which will produce the same result as it does currently. With devtoolNamespace set to a value it produce the format you stated: webpack:///[namespace]/[resourcePath].... The [namespace] placeholder need to be added to the moduleFilenameTemplate option.
  3. On long term this will be integrated into webpack, so this is not an important issue. On short term we can add the namespace option to the style-loader too to generate source-maps in the same namespace.

@MagicDuck
Copy link
Contributor Author

MagicDuck commented Oct 13, 2017

@sokra thanks for the reply! Having output.devtoolNamespace option makes sense to me. For number 3, I guess I didn't really communicate that properly. The css-loader doesn't even put it's stuff under webpack:// as far as I can see: https://github.com/webpack-contrib/css-loader/blob/master/lib/loader.js#L117
image
(Ignore some of the weird absolute paths under webpack://, It's cause my package.json is pointing to a local package)

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Oct 14, 2017

@MagicDuck Feel free to open an Issue /PR at style-loader/css-loader in case any work is required there :)

@MagicDuck
Copy link
Contributor Author

I can do that. Just wanted to get to get @sokra 's opinion since he has the context to give a wholistic approach to the solution rather than piecemeal everywhere.

@sokra
Copy link
Member

sokra commented Oct 16, 2017

In my opinion a prefix for the CSS Source Maps does make sense. Maybe we shouldn't merge it into webpack:// because it would conflict with the JS files. Maybe webpack-css:// make sense here. I need to be configurable, because some tools like create-react-app don't like the prefix and like to use absolute resource paths instead.

MagicDuck pushed a commit to MagicDuck/webpack that referenced this issue Oct 17, 2017
When loading multiple libraries built with webpack, you can run into
collisions of the sourcemap file paths. For examle, both have
"webpack:///src/index.js".

This change addresses the problem by introducing a new output option
`output.devtoolNamespace` which defaults to `output.library` when
not specified. The defaults moduleFilenameTemplates in all the
sourcemap plugins have been modified to start with:
"webpack://[namespace]/...", where [namespace] will be replaced by
the `output.devtoolNamespace`.

Notice that there are only two slashes following "webpack:" now.
This is to make it behave just as before when not building with a
namespace. When building with a namespace you only get the two
slashes, but from what I've seen the chrome dev tools only care
about the first 2 slashes anyways.

webpack#5767
MagicDuck pushed a commit to MagicDuck/webpack that referenced this issue Oct 17, 2017
When loading multiple libraries built with webpack, you can run into
collisions of the sourcemap file paths. For examle, both have
"webpack:///src/index.js".

This change addresses the problem by introducing a new output option
`output.devtoolNamespace` which defaults to `output.library` when
not specified. The defaults moduleFilenameTemplates in all the
sourcemap plugins have been modified to start with:
"webpack://[namespace]/...", where [namespace] will be replaced by
the `output.devtoolNamespace`.

Notice that there are only two slashes following "webpack:" now.
This is to make it behave just as before when not building with a
namespace. When building with a namespace you only get the two
slashes, but from what I've seen the chrome dev tools only care
about the first 2 slashes anyways.

Discussed with sokra here:
webpack#5767
@MagicDuck
Copy link
Contributor Author

PR here: #5844 :)

MagicDuck added a commit to MagicDuck/webpack that referenced this issue Oct 18, 2017
When loading multiple libraries built with webpack, you can run into
collisions of the sourcemap file paths. For examle, both have
"webpack:///src/index.js".

This change addresses the problem by introducing a new output option
`output.devtoolNamespace` which defaults to `output.library` when
not specified. The defaults moduleFilenameTemplates in all the
sourcemap plugins have been modified to start with:
"webpack://[namespace]/...", where [namespace] will be replaced by
the `output.devtoolNamespace`.

Notice that there are only two slashes following "webpack:" now.
This is to make it behave just as before when not building with a
namespace. When building with a namespace you only get the two
slashes, but from what I've seen the chrome dev tools only care
about the first 2 slashes anyways.

Discussed with sokra here:
webpack#5767
MagicDuck added a commit to MagicDuck/webpack that referenced this issue Oct 18, 2017
When loading multiple libraries built with webpack, you can run into
collisions of the sourcemap file paths. For examle, both have
"webpack:///src/index.js".

This change addresses the problem by introducing a new output option
`output.devtoolNamespace` which defaults to `output.library` when
not specified. The defaults moduleFilenameTemplates in all the
sourcemap plugins have been modified to start with:
"webpack://[namespace]/...", where [namespace] will be replaced by
the `output.devtoolNamespace`.

Notice that there are only two slashes following "webpack:" now.
This is to make it behave just as before when not building with a
namespace. When building with a namespace you only get the two
slashes, but from what I've seen the chrome dev tools only care
about the first 2 slashes anyways.

Discussed with sokra here:
webpack#5767
@MagicDuck
Copy link
Contributor Author

also filed issue on the css-loader side: webpack-contrib/css-loader#622

@adrianromanko
Copy link

@MagicDuck Thanks for adding this options. I'm waiting for your namespace PR request to go through.

@MagicDuck
Copy link
Contributor Author

@adrianromanko my pleasure 😀. I looks it was merged a while ago. Its probably available in webpack 4.
This issue should probably be closed...

@jazdw
Copy link

jazdw commented Jun 18, 2018

Thanks for this, its useful when you build a library with multiple entry points. I use a library option like this library: '[name]' and without setting devtoolNamespace it shows up in the Chrome debugger as %5Bname%5D.

@MagicDuck
Copy link
Contributor Author

@jazdw that sounds like a bug to me. You should file an issue I think. Closing this one.

@airtonix
Copy link

@jazdw Did you end up creating that ticket, also experiencing the same problem:

many entrypoints, many output bundles, each being a umd library with sourcemaps that all get called [name] in Chrome.

@jazdw
Copy link

jazdw commented Feb 19, 2020

@airtonix no I didn't sorry

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

No branches or pull requests

8 participants