Skip to content

sass.importer doesn't work correctly on browser if it's used against sass.compileFile #129

@Zardoz89

Description

@Zardoz89

On browser (tested with Firefox and Chrome), If i try to use sass.importer with sass.compilefile, sass.js hangs and eventually throws a "uncaught exception: abort(31). Build with -s ASSERTIONS=1 for more info."

To reproduce :

index.html

<html>
  <head>
    <script src="node_modules/sass.js/dist/sass.js"></script>
    <script>
        var sass = new Sass();

        sass.importer(function(request, done) {
          console.log("importer request: " , request);
          if (request.path) {
            // Sass.js already found a file,
            // we probably want to just load that
            done();
          } else if (request.current === 'content') {
            // provide a specific content
            // (e.g. downloaded on demand)
            done({
              content: '.some { content: "from anywhere"; }'
            })
          } else if (request.current === 'error') {
            // provide content directly
            // note that there is no cache
            done({
              error: 'import failed because bacon.'
            })
          } else {
            // let libsass handle the import
            done();
          }
        });

        var base = '../../../';
        var directory = '';

        // preload a set of files
        sass.preloadFiles(base, directory, ["scss/main.scss"], function callback() {

          sass.compile(`@import "error"; div { background-color: green;}`, function(result) {
            console.log("compile : ", result);
          });

          sass.compileFile("scss/main.scss", function(result) {
            console.log("compileFile : ", result);
          });
        });
    </script>
  </head>
  <body>
  </body>
</html>

scss/main.scss

@import "error";

div {
  background-color: red;
}

Console output :

// Here works OK as compiles with sass.compile
11:07:45.518 importer request:  Object { current: "error", previous: "stdin", resolved: "/sass/error", path: null, options: null }
11:07:45.564 compile :  Object { status: 1, file: "stdin", line: 1, column: 9, message: "import failed because bacon.", formatted: "Error: import failed because bacon.\n        on line 1:9 of /stdin\n>> @import \"error\"; div { background-color: green;}\n   --------^\n" }

// Here hangs when tries with sass.compileFile
11:07:45.571 importer request:  Object { current: "error", previous: "/sass/scss/main.scss", resolved: "/sass/scss/error", path: null, options: null }
11:08:29.059 31 sass.worker.js:5:15099
11:08:29.059 31 sass.worker.js:5:15109
11:08:29.060
uncaught exception: abort(31). Build with -s ASSERTIONS=1 for more info. sass.worker.js:5:416751
    invoke_vii http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:5
    $Y http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:24
    fFa http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:27
    Eda http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:24
    sxa http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:27
    lfa http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:24
    Lc http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:23
    My http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:10
    fw http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:10
    Lc http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:23
    qz http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:10
    resume http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:5
    _emscripten_sleep http://localhost:1234/node_modules/sass.js/dist/sass.worker.js:5

If you change '@import "error";' for '@import "content";' fails on the same way. Same thing if you remove the call to sass.compile and keep alone the sass.compileFile .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions