Giter VIP home page Giter VIP logo

Comments (1)

Indigo744 avatar Indigo744 commented on September 2, 2024

Ok I understand what was the issue.

TL/DR

SCSS file was encoded in UTF8-BOM. Switching to UTF8 (without BOM) resolved the issue.

Explanation

I created a single js file containing only the following line:

const sassExtract = require('sass-extract');
const renderedSass = sassExtract.renderSync({ file: "file.scss" });
console.log(renderedSass);

And I ran it with node test.js (instead of doing it through webpack).
It allowed me to get the real error:

.\node_modules\gonzales-pe\lib\gonzales.js:812
            throw new ParsingError(e, css);
            ^
Parsing error: Please check validity of the block starting from line #1

After fiddling with my scss file, I discover that it was stored in UTF8 with a BOM (a byte-order mask).
It seems that the Gonzales lib is choking on this byte.

Removing the BOM (i.e. storing as UTF8 only) resolve the issue.

Workaround

Workaround 1 : remove BOM of SCSS file

Workaround 2: read file with fs, remove BOM and pass it directly to the lib:

const sassExtract = require('sass-extract');
const renderedSass = sassExtract.renderSync({
    data: fs.readFileSync("file.scss", 'utf-8').replace(/^\uFEFF/, '')
});
console.log(renderedSass);

Solution taken from nodejs/node-v0.x-archive/issues/1918

Fix

I think the issue lies in the sass-extract library. Gonzales API expects a string.
The BOM is not part of the text. It is part of a file specification to identify an UTF8 encoded file.

Sass-extract should strip any BOM before passing it to the parser.

from sass-extract.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.