Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zardoz89 opened this issue Jul 26, 2020 · 2 comments

Comments

@Zardoz89
Copy link

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 .

@peekieisabear
Copy link

I know this is 3 years old but did you ever find a solution to this?

@Zardoz89
Copy link
Author

Sadly no. You are free to try to find a solution to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants