question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel parses and removes sourceMappingURL from input

See original GitHub issue

Bug Report

Current Behavior

I have some code that generates JavaScript files and includes the string //# sourceMappingURL=. Babel appears to remove this string and the remainder of the line before parsing.

Input Code

const comment = `//# sourceMappingURL=${path.basename(
  sourceMapFilename
)}`

Babel REPL

Output Code

const comment = `
  sourceMapFilename
)}`;

Expected behavior/code

//# sourceMappingURL= should not have special meaning inside of a template literal, and should be included in the generated output

const comment = `//# sourceMappingURL=${path.basename(sourceMapFilename)}`;

Babel Configuration (.babelrc, package.json, cli command)

None, see REPL link.

Environment

  • Babel version(s): v7.4.2
  • How you are using Babel: repl

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
loganfsmythcommented, Mar 30, 2019

@nicolo-ribaudo I think you misread this one. We’re removing the comment-like content of a JS string, which is not right.

The logic for stripping sourceMappingURL must not verify that it’s in a file-end comment token, and instead just look for the string itself.

@also Seems reasonable for us to fix this. For now I’d split the string into two pieces and concatenate with + so we don’t match the comment string, e.g.

const comment = `//# ` + `sourceMappingURL=${path.basename(
0reactions
nicolo-ribaudocommented, Mar 31, 2019

It needs to be fixed in the convert-source-map package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options - Babel.js
Babel's default is to generate a string and a sourcemap, but in some ... false can improve parsing performance if the input AST...
Read more >
Webpack Module Warning: Failed to parse source map from ...
As a sort of fix I removed the source-map-parser and the warning disappeared. Is it possible this issue happened because a webpack watch...
Read more >
source-map-loader - webpack
Allows you to specify the behavior of the loader for SourceMappingURL comment. ... true or 'consume' - consume the source map and remove...
Read more >
How to use the rollup-plugin-sourcemaps function in ... - Snyk
To help you get started, we've selected a few rollup-plugin-sourcemaps examples, based on popular ways it is used in public projects.
Read more >
@babel/preset-react | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found