-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
sourceMappingURL directive can fail if a bundled module specifies the directive #772
Comments
I don't think it's Instead it's job is to bundle your modules together. If you tell browserify to combine the source maps via You should write a transform to remove source maps instead of making this part of browserify itself. This should be a fairly simple task, just use convert-source-map to find the source map via a regex and remove them from each file. |
To clarify, the behaviour I'm seeing occurs only when using |
Ah that's different then, it is supposed to find them when given So I'm not sure why in your case it doesn't find it. |
I was getting the issue in https://github.com/davidmason/work-life It needs a couple of tweaks to work in browserify:
The package that is not having its source map processed is https://github.com/meryn/performance-now (brought in via crtrdg-gameloop <- raf-stream <- raf <- performance-now) |
I think I have the same issue. I compile TypeScript using an external compiler ( So I have a directory with commonJS JavaScript modules, each with a Then I use browserify with When I look into the bundled JavaScript I see the original I tried it with plain browserify (and a base64 decoder to inspect the inline sourcemap) and also with Note I'm on working on windows, if that matters for anything. |
I created a minimal demo for this: https://github.com/Bartvds/demo-typescript-browserify It uses grunt and grunt-ts to compile two TypeScript files to commonJS modules, and then a simple inline task to run browserify+exorcist to bundle them. For your review I checked-in the JS code: The intermediate JavaScript: https://github.com/Bartvds/demo-typescript-browserify/tree/master/tmp And the bundle file + exorcised sourcemap: https://github.com/Bartvds/demo-typescript-browserify/tree/master/dist As you see the bundle file still has the original directives, and the sourcemap points to the intermediate files instead of TypeScript sources. |
|
According to the spec (https://goo.gl/UQJKOW) the source map comment should be at the very end of the file. Browser's adhere to that, i.e. use the last source map in the file. Browserify's --debug adds a source map at the bottom of the compiled file, but currently fails to combine that with the source map referenced in script.js. This is a bug in Browserify, see issue browserify/browserify#772. Our test case thus only worked by accident, for the user in the browser only "script.js" shows up, not "script.coffee" as it should. So for the time being, we should just remove the --debug flag from the build and re-enable once browserify fixes that issue.
According to the spec (https://goo.gl/UQJKOW) the source map comment should be at the very end of the file. Browser's adhere to that, i.e. use the last source map in the file. Browserify's --debug adds a source map at the bottom of the compiled file, but currently fails to combine that with the source map referenced in script.js. This is a bug in Browserify, see issue browserify/browserify#772. Our test case thus only worked by accident, for the user in the browser only "script.js" shows up, not "script.coffee" as it should. So for the time being, we should just remove the --debug flag from the build and re-enable once browserify fixes that issue.
Hi guys. Are there any news on this? Since libraries like Angular2 use TypeScript as a first class citizen, I think we will see a lot more modules on npm developed in Typescript. Personally, I like having the possibility to step into the libraries I'm using when debugging, so I think this feature is really useful. |
I'm also running into this issue. I have a module dependency that is pre-compiled with its own sourcemap and when I run browserify with |
+1 same issue here. |
+1 for this issue |
+1 |
1 similar comment
+1 |
I guess even if we don't combine sourcemaps yet, we should eliminate sourceMappingURL directive from libraries when building the bundle with --debug. This way we won't see annoying warnings in console when building a library that has sourceMappingURL directives inside. |
Is the correct behaviour that preexisting sourcemaps for files that are being bundled by browserify should be integrated into the final bundle sourcemap -- that is to say that sourcemaps should reverse all compilation steps and not just the browserify step? If this is so what needs to be done to fix the issue? I'd be happy to pitch in with a PR if needed. Can someone familiar with browserify provide any additional details? |
+1 |
This question from Stack Overflow contains some workarounds that might be useful to other developers. |
As described in the stack overflow article, I was able to use the sorcery package to fix sourcemaps generated by browserify and work around this issue. |
That was my expectation from browserify too - to consume sourcemaps provided by input files, but turns out it just ignores them. swcify sourcemaps support is blocked by that. |
browser-pack should merge source maps correctly afaik. transforms are individually responsible for reading input source maps and outputting merged ones. i'm not sure what specifically is going wrong for people in this issue, but with a repro i could take a look at it |
Hi @goto-bus-stop, I'm afraid I don't have a public example at the moment, but I'll do my best to describe my experience. I have a TypeScript library and a main project which references the library via TypeScript project references, so whenever I run Since the library is built via //# sourceMappingURL=myfile.js.map` The var commentRx = /^\s*\/(?:\/|\*)[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+;)?base64,(.*)$/mg; My workaround as of yesterday is to use the
Having said that, it would be very nice if all of this could just work out of the box :) |
I just added a sample repo here: https://github.com/jeremija/lerna-ts-example. Instructions provided in EDIT I just realized that there is an easier way to do this in TypeScript, without the need for Still, |
@goto-bus-stop nvm, swc generates wrong sourcemaps, swc-project/swc#349, so I was thinking browserify does not support them. It does. |
Apparently it works only if you inline the source maps into browserify’s input files. But then it works well. |
Did you know? This bundler is barely ever used outside of legacy projects since 2016. |
Philip Polkovnikov dixit:
Did you know? This bundler is barely ever used outside of legacy projects since 2016.
No reason not to fix things, or at least inform people about
workarounds, no? I happen to have inherited such a legacy
project, and it works exceedingly well otherwise, with a few
minor workarounds (like removing the otherwise mandatory
trailing newline from input files, or it’ll have too much
whitespace between the modules, but that’s cosmetic).
bye,
//mirabilos
--
"Using Lynx is like wearing a really good pair of shades: cuts out
the glare and harmful UV (ultra-vanity), and you feel so-o-o COOL."
-- Henry Nelson, March 1999
|
If a bundled module has a
sourceMappingURL
directive, browserify will leave it intact, which appears to be worthless or harmful towards getting source maps to work properly in browsers.Ideally, when browserify is generating source maps it would detect
sourceMappingURL
directives in bundled modules and include the contents of the targeted source maps in the bundle's source map. At very least, the directives should be removed during bundling to prevent possible conflicts.The same issue is present in webpack, so I will refer to the bug report there rather than duplicate it: webpack/webpack#273
The only difference between browserify and webpack with this issue is that browserify does not use the deprecated
//@
form of the directive, so it will only see the issue of duplicatesourceMappingURL
directives when the bundled module has a directive in the form//# sourceMappingURL=...
.The text was updated successfully, but these errors were encountered: