sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.9k stars 352 forks source link

Bad state error when using `meta.apply` and compile with `render` #2151

Closed bluwy closed 8 months ago

bluwy commented 8 months ago

When using the deprecated render API to process sass files (Vite still uses it), and also using meta.apply, it fails with (raw log):

Error: Bad state: Can't access __parent outside of a module.
    at Object.wrapException (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:1252:43)
    at _EvaluateVisitor2._async_evaluate0$_assertInModule$1$2 (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:80473:15)
    at _EvaluateVisitor2._async_evaluate0$_assertInModule$2 (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:80476:19)
    at /Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:81047:34
    at _wrapJsFunctionForAsync_closure.$protected (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:4022:15)
    at _wrapJsFunctionForAsync_closure.call$2 (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:33914:12)
    at _awaitOnObject_closure.call$1 (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:33902:32)
    at Object._rootRunUnary (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:4408:18)
    at StaticClosure.<anonymous> (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:115526:16)
    at _CustomZone.runUnary$2$2 (/Users/bjorn/Work/repros/vite-sass-test/node_modules/.pnpm/sass@1.69.5/node_modules/sass/sass.dart.js:35338:39)

Using compileString works fine. I'm not sure if it is intentional that this new feature doesn't work with the deprecated render API, but if so I think that's fair and just checking here.

Here's a repro comparing compileString and render: https://stackblitz.com/edit/stackblitz-starters-tirkhu?file=index.js (run node index.js to see error)

This was originally reported at https://github.com/vitejs/vite/issues/15443

nex3 commented 8 months ago

Interestingly, renderSync() also works here, so it looks like it has something to do with the asynchrony specifically. Thanks for reporting this, I'll take a look.

bluwy commented 8 months ago

Thanks for the quick fix!