-
Notifications
You must be signed in to change notification settings - Fork 359
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
Unable to resolve files inside Jest #710
Comments
If this is only an issue within Jest, I suggest filing an issue there. I'm not familiar with Jest, and without a reproduction that uses the raw Sass API there's not much I can do. |
@cshawaus Did you find a solution to this? |
@cshawaus @justinappler I tried the same setup and had the same problem. |
I also encountered the same issue. I documented my findings in true repo, but I'm duplicating it here b/c the root problem is an interaction between jest (when using As others reported, using Note that I only saw this specific issue on Linux - on windows the tests work as expected with jest and dart-sass. However, I also experienced another, almost surely related problem on Windows - the dart-sass @import / @use file resolution failed to find scss files in the same directory. So I (before discovering the testEnvironment: node workaround) had written my own importer, which fixed up the file resolution. After switching to Given all this, it seems safe to conclude that dart-sass file or path resolution doesn't work correctly within jest when using I can provide a repro if helpful (without using sass-true), but I'm not able to isolate the problem to just sass.dart.js - the repro would include jest and sass.dart.js. |
Dart Sass uses many Node APIs, so I'm surprised it does anything outside a Node environment. |
The suggested workaround does not work with Create React App because it's not possible to override the My solution was to switch to node-sass. |
How does Node Sass work without a Node environment? |
@nex3 Jest does not run tests in a browser. It uses jsdom ("fake DOM") to mimic browser environment. So, it is still running in a Node environment. I tracked the bug down to this line: Line 133 in 7160b64
Edit: I created a reproduction of the issue at https://github.com/apaatsio/dart-sass-issue-710
|
@apaatsio Thanks for tracking that down! It looks like it's another example of a longstanding thorn in our side, dart-lang/sdk#27979. |
I just ran into this or something related to this myself. I found in the Jest docs you can use this comment to change the test environment per file. As mentioned previously in this thread, you can also change test environment project-wise.
From the docs: https://jestjs.io/docs/en/configuration#testenvironment-string. Apparently jsdom is somehow incompatible with the file system. Anyway, by telling Jest you want Example code: /**
* @jest-environment node
*/
import sass from "sass";
test("test", () => {
const result = sass.renderSync({
file: "src/file.scss",
});
expect(result.css.toString()).toBe("...")
}) |
I had the same issue as @zaydek the explaination by @apaatsio is correct. Can confirm that it is not an issue in dart-sass, but jest. Just for anyone having the same issue: "jest": {
"testEnvironment": "node"
}, |
If changing the testEnvironment isn't an option for you, this kinda worked for us: delete window.location;
window.location = {
href: __dirname
} It could then correctly find the file. However, we then ran into issues with importing files, so unless that can be solved this might only work if your file is standalone. |
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
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
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
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
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
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
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
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
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
I'm currently messing around with Sass True and Dart Sass but I'm running into an issue by which the
renderSync
method in Dart Sass is unable to resolve any paths I give to it. Please see the error below.I've gone through the implementation several times and I can't see where I'm going wrong as it seems like such a simple example that I expect to work since
sass-loader
is working as expected with Dart Sass.Below is the code in question which runs inside Jest but I have also tried inside a vanilla node script and it works just fine so I'm not sure if it is a Jest or Dart Sass issue.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: