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.

Dealing with previous sourcemaps

See original GitHub issue

Just a quick question about a problem I encountered. Here is a structure:

_ assets
    |_ dist
        |_ main.css
        |_ main.css.map
    |_ sources
        |_ scss
            |_ main.scss
            |_ _partials.scss

When node-sass parses main.scss, it creates main.css and main.css.map. In sourcemaps file, sources are relative, like for example: ../sources/scss/main.scss, but there is not sourceRoot. When postcss tries to use previous sourcemaps, it rewrites ../sources/scss/main.scss to ../sources/sources/scss/main.scss and it fails.

In map.generator.js:115, this.map.applySourceMap(map, from, this.relative(root)):

  • from is equal to ../sources/scss/main.scss
  • this.relative(root) is equal to ../sources/scss while it should be equal to ../scss to make it work.

Any idea where the problem is?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
mturnwallcommented, Jul 26, 2017

I think I found a solution using the prev key. When I first used prev I would get an error telling me that that it was an unsupported format.

    processor.process(css.css, {
            from: `./src/sass/${sassFilename}.scss`,
            to: `${cssDir}/master.css`,
            map: {
                prev: css.map,
                inline: false,
            },
        })

css.map is a properly formatted sourcemap from node-sass. The Postcss documentation says that prev accepts an object.

If I convert the map to a string then prev works just fine.

    processor.process(css.css, {
            from: `./src/sass/${sassFilename}.scss`,
            to: `${cssDir}/master.css`,
            map: {
                prev: css.map.toString(),
                inline: false,
            },
        })
0reactions
mturnwallcommented, Jul 26, 2017

I’m having the same issue. I have a single scss file that imports other scss files. The sourcemap from node-sass properly lists all the scss files in the sources array of the sourcemap. Once the css is run through Postcss the sources array now only points to the single scss file that imports everything.

This is my main scss file.

@import 'easing';

@import '../../node_modules/susy/sass/susy',
        '../../node_modules/css-wipe/index'; // css reset

@import 'config';

@import 'typography',
        'buttons',
        'forms';

@import 'global';

Here are my scripts for node-sass and postcss

function compileSass() {
    return sass.renderSync({
        file: `./src/sass/${sassFilename}.scss`,
        outFile: `${cssDir}/master.css`,
        outputStyle: 'expanded',
        sourceMap: true,
    });
}

function processCss(css) {
    const processor = postcss([autoprefixer]);
    processor.process(css.css, {
            from: `./src/sass/${sassFilename}.scss`,
            to: `${cssDir}/master.css`,
            map: {
                inline: false,
            },
        })
// mode code here to write files to disk

Here is what Postcss outputs for the sourcemap

{"version":3,"sources":["../../src/sass/master.scss"]...

How do I get Postcss to still reference all the correct scss files that are imported by the main scss file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source maps and how it works - Ehsan Gazar
Source maps can be convenient during development. They provide better means to debug applications as you can still examine the original code ...
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 >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
4 Reasons Why Your Source Maps are Broken · Missing or incorrect source map directive · Missing original source files · Bad source...
Read more >
JavaScript Debugging with Sourcemaps - TrackJS
The main purpose of sourcemaps is to aid debugging. Basically, if there's an error in the generated code file, the map can tell...
Read more >
Should I Use Source Maps in Production? | CSS-Tricks
A “source map” is a special file that connects a minified/uglified version of an asset (CSS or JavaScript) to the original authored version....
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