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.

map.sourcesContent doesn't work together with map.from

See original GitHub issue
const postcss = require('postcss');
const autoprefixer = require('autoprefixer');

const options = {
  from: 'src/test.css',
  to: 'src/test.css!postcss',
  map: {
    inline: false,
    annotation: false,
    sourcesContent: true,
    from: 'src/test.css'
  }
};

const instance = postcss([ autoprefixer({ browsers: '>0%' }) ]);

const result = instance.process('.test { border-radius: 5px }', options);

console.log(result.map.toJSON());

code below will produce sourcesContent: [ null ] instead of sourcesContent: [ '...' ] but will produce correct source name src/test.css.

If i will remove from option then sourcesContent will have correct value but sources will have test.css instead of src/test.css.

So there is no way to keep correct source name together with source content.

Looks like a two defects:

  • options.from with full path truncated to basename by default and source map looses original source file path
  • workaround with options.map.from keeps correct source file path but doesn’t work well with options.map. sourcesContent = true (breaks source content)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
yuriyostapenkocommented, Nov 17, 2016

Hi, I think I hit the same issue when running postcss on node-sass output. if map.from is set, the resulting .map file only references the empty virtual file, while all original sass maps are gone.

0reactions
aicommented, Apr 14, 2017

I found problem. It was because of wrong content of opts.map.from. It should be relative from to (in this case it should be test.css).

I fixed docs: https://github.com/postcss/postcss/commit/30ac96f1a93484a591ba94a98e6a8aba519b3d37

opts.map.from is low-level option for rare edge cases. You should not use it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Reasons Why Your Source Maps are Broken - Sentry Blog
Source maps are awesome... when they work. ... This likely means that your source map doesn't contain or link to your original source...
Read more >
Do source maps include the source text? - Stack Overflow
Source maps can optionally include the original source. From the spec, sourcesContent is "An optional list of source content, ...
Read more >
Source-maps could be revealing your private project files
The CLI will generate bundle files automatically along with files called “source-maps”. Every time you make production build of your app, “.js.
Read more >
Use a source map — Firefox Source Docs documentation
A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original...
Read more >
Anatomy of source maps | Bugsnag Blog
Learn how source maps work by examining their inner workings through ... JS, however, doesn't provide a way (yet) to import code from...
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