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

Importing sass file from 3rd party lib with data url causes crash #4026

Closed
6 tasks done
bgoscinski opened this issue Jun 29, 2021 · 4 comments
Closed
6 tasks done

Importing sass file from 3rd party lib with data url causes crash #4026

bgoscinski opened this issue Jun 29, 2021 · 4 comments

Comments

@bgoscinski
Copy link
Contributor

bgoscinski commented Jun 29, 2021

Describe the bug

I'm trying to import a *.sass (written in the indented syntax) file from quasar library in my project but as soon as I add proper import in any of my scss file the dev server crashes. I believe it might have something to do with sass/dart-sass#1138.

I found that this change prevents sass crash:

diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts
index 1f123e8d..c4682648 100644
--- a/packages/vite/src/node/plugins/css.ts
+++ b/packages/vite/src/node/plugins/css.ts
@@ -962,7 +962,10 @@ const scss: SassStylePreprocessor = async (
   const internalImporter: Sass.Importer = (url, importer, done) => {
     resolvers.sass(url, importer).then((resolved) => {
       if (resolved) {
-        rebaseUrls(resolved, options.filename, options.alias).then(done)
+        rebaseUrls(resolved, options.filename, options.alias).then(res => {
+          res.file = 'file:///' + res.file
+          done(res)
+        })
       } else {
         done(null)
       }

Reproduction

I managed to reduce the reproduction steps to this: https://github.com/bgoscinski/vite-sass-bug-repro

System Info

I can't test on any other OS than windows 10.

  System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
    Memory: 5.94 GB / 15.86 GB
  Binaries:
    Node: 16.2.0 - C:\.tools\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.18.1 - C:\.tools\nodejs\npm.CMD
  Browsers:
    Chrome: 91.0.4472.114
    Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.59)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    vite: 2.3.8 => 2.3.8

Used Package Manager

npm

Logs

$ npm run build

> build
> vite build

vite v2.3.8 building for production...
transforming (1) index.htmlC:\dev\sass-bug\node_modules\sass\sass.dart.js:27420
      throw error;
      ^

Invalid argument(s): Uri c:%5Cdev%5Csass-bug%5Cnode_modules%5Cvite%5Cfoo.sass must have scheme 'file:'.
    at Object.wrapException (C:\dev\sass-bug\node_modules\sass\sass.dart.js:1231:17)
    at WindowsStyle.pathFromUri$1 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:33230:17)
    at StaticClosure.fromUri (C:\dev\sass-bug\node_modules\sass\sass.dart.js:16163:37)
    at Object.NullableExtension_andThen0 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:18504:40)
    at Object._wrapException (C:\dev\sass-bug\node_modules\sass\sass.dart.js:13047:14)
    at _render_closure1.call$2 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:81775:21)
    at _RootZone.runBinary$3$3 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:27547:18)
    at _FutureListener.handleError$1 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:26096:19)
    at _Future__propagateToListeners_handleError.call$0 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:26394:49)
    at Object._Future__propagateToListeners (C:\dev\sass-bug\node_modules\sass\sass.dart.js:4541:77) {
  dartException: <ref *1> ArgumentError {
    _hasValue: false,
    invalidValue: null,
    name: null,
    message: "Uri c:%5Cdev%5Csass-bug%5Cnode_modules%5Cvite%5Cfoo.sass must have scheme 'file:'.",
    '$thrownJsError': <ref *2> Invalid argument(s): Uri c:%5Cdev%5Csass-bug%5Cnode_modules%5Cvite%5Cfoo.sass must have scheme 'file:'.
        at Object.wrapException (C:\dev\sass-bug\node_modules\sass\sass.dart.js:1231:17)
        at WindowsStyle.pathFromUri$1 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:33230:17)
        at StaticClosure.fromUri (C:\dev\sass-bug\node_modules\sass\sass.dart.js:16163:37)
        at Object.NullableExtension_andThen0 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:18504:40)
        at Object._wrapException (C:\dev\sass-bug\node_modules\sass\sass.dart.js:13047:14)
        at _render_closure1.call$2 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:81775:21)
        at _RootZone.runBinary$3$3 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:27547:18)
        at _FutureListener.handleError$1 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:26096:19)
        at _Future__propagateToListeners_handleError.call$0 (C:\dev\sass-bug\node_modules\sass\sass.dart.js:26394:49)
        at Object._Future__propagateToListeners (C:\dev\sass-bug\node_modules\sass\sass.dart.js:4541:77) {
      dartException: [Circular *1],
      '$cachedTrace': _StackTrace {
        _exception: [Circular *2],
        _trace: "Invalid argument(s): Uri c:%5Cdev%5Csass-bug%5Cnode_modules%5Cvite%5Cfoo.sass must have scheme 'file:'.\n" +
          '    at Object.wrapException (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:1231:17)\n' +
          '    at WindowsStyle.pathFromUri$1 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:33230:17)\n' +
          '    at StaticClosure.fromUri (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:16163:37)\n' +
          '    at Object.NullableExtension_andThen0 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:18504:40)\n' +
          '    at Object._wrapException (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:13047:14)\n' +
          '    at _render_closure1.call$2 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:81775:21)\n' +
          '    at _RootZone.runBinary$3$3 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:27547:18)\n' +
          '    at _FutureListener.handleError$1 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:26096:19)\n' +
          '    at _Future__propagateToListeners_handleError.call$0 (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:26394:49)\n' +
          '    at Object._Future__propagateToListeners (C:\\dev\\sass-bug\\node_modules\\sass\\sass.dart.js:4541:77)'
      }
    }
  }
}

Validations

@miccycn
Copy link

miccycn commented Jul 28, 2021

Same issue. repro in windows, but can't repro in Mac/Linux.

@lingdle-hi
Copy link

Same issue. repro in windows, but can't repro in Mac/Linux.

Me too

@tolu
Copy link
Contributor

tolu commented Aug 5, 2021

Seeing the same issue although it is not entirely remedied by the proposed solution, yes the first sass import works, but further relative imports from the 3rd party file fail...

For me it's not 3rd party code but just an aliased import in a monorepo.

@bgoscinski
Copy link
Contributor Author

sass/dart-sass#1138 has been fixed in sass@1.38.0 and it seems to resolve this problem as well 🎊🎉

@github-actions github-actions bot locked and limited conversation to collaborators Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants