Skip to content

Commit

Permalink
Fix Sass compilation in tests
Browse files Browse the repository at this point in the history
There is a bug where `sass.compile` will throw with an extremely
unhelpful error trace when running in Jest [[1]].

>     TypeError: J.getInterceptor$ax(...).map$1$1 is not a function
>
>     at Object.map$1$1$ax (node_modules/sass/sass.dart.js:24513:44)
>     at listDir_closure0.call$0 (node_modules/sass/sass.dart.js:87066:18)
>     at Object._systemErrorToFileSystemException0 (node_modules/sass/sass.dart.js:20776:23)
>     at Object.listDir0 (node_modules/sass/sass.dart.js:20771:16)
>     at _realCasePath_helper_closure0.call$0 (node_modules/sass/sass.dart.js:84710:34)
>     at JsLinkedHashMap.putIfAbsent$2 (node_modules/sass/sass.dart.js:27273:24)
>     at _realCasePath_helper0.call$1 (node_modules/sass/sass.dart.js:84699:32)
>     at _realCasePath_helper_closure0.call$0 (node_modules/sass/sass.dart.js:84706:35)
>     at JsLinkedHashMap.putIfAbsent$2 (node_modules/sass/sass.dart.js:27273:24)
>     at _realCasePath_helper0.call$1 (node_modules/sass/sass.dart.js:84699:32)

It has been suggested
that it is related to `path.absolute` being overridden by the jsdom
environment [[2]], but the workaround of using the "node" environment
does not solve the issue for us.

Instead, what did work is using the legacy API [[3]]. I'm not sure why
this is, but it seems to do the trick. Note that with the legacy API,
the file path is part of the options object, rather than being the
first argument. If you forget to change the call signature, you will get
a different unhelpful error message:

> NoSuchMethodError: method not found: 'call'

[1]: sass/dart-sass#1692
[2]: sass/dart-sass#710 (comment)
[3]: https://sass-lang.com/documentation/js-api#legacy-api
  • Loading branch information
lfdebrux committed May 19, 2022
1 parent 6e25d8f commit 1fdc78a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build/run-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function sass (sassPath, cssPath) {
if (!file.endsWith('.scss')) return

try {
const result = sass.compile(`${sassPath}/${file}`, {
const result = sass.renderSync({
file: `${sassPath}/${file}`,
logger: sass.Logger.silent,
loadPaths: [__dirname],
sourceMap: true,
Expand Down

0 comments on commit 1fdc78a

Please sign in to comment.