browserify: sourceMappingURL directive can fail if a bundled module specifies the directive
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: https://github.com/webpack/webpack/issues/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 duplicate sourceMappingURL directives when the bundled module has a directive in the form //# sourceMappingURL=....
About this issue
- Original URL
- State: open
- Created 10 years ago
- Reactions: 2
- Comments: 26 (2 by maintainers)
Commits related to this issue
- fix: remove --debug flag for browserify. 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... — committed to mprobst/node-source-map-support by mprobst 9 years ago
- fix: remove --debug flag for browserify. 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... — committed to mprobst/node-source-map-support by mprobst 9 years ago
I just added a sample repo here: https://github.com/jeremija/lerna-ts-example. Instructions provided in
README.md.EDIT I just realized that there is an easier way to do this in TypeScript, without the need for
sourceify. ThesourceMapproperty needs to be removed fromtsconfig.json, and bothinlineSourceMapandinlineSourcesneed to be set totrue.Still,
sourceifyis useful in cases of 3rd-party libraries which might have source map file references instead of inlined sources.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
@goto-bus-stop nvm, swc generates wrong sourcemaps, https://github.com/swc-project/swc/issues/349, so I was thinking browserify does not support them. It does.
I think I have the same issue.
I compile TypeScript using an external compiler (
grunt-ts, because the existing browserify TypeScript transforms/plugins are all borked).So I have a directory with commonJS JavaScript modules, each with a
//# sourceMappingURLdirective and a map file pointing to the TypeScript sources.Then I use browserify with
debug: trueon the main file, but it ignores the existing directives and the bundle’s sourcemap points to the intermediate commonJS JavaScript instead of the original TypeScript.When I look into the bundled JavaScript I see the original
//# sourceMappingURLdirectives are not removed.I tried it with plain browserify (and a base64 decoder to inspect the inline sourcemap) and also with
exorcistto output a separate file.Note I’m on working on windows, if that matters for anything.