Skip to content

Commit 262961c

Browse files
authored
Check the fs library to determine if we're on Node.js (#2033)
This fixes an issue where some environments (like VS Code) define `process` but don't load the Node.js entrypoint, causing Sass to think it's running under Node without access to its Node dependencies. Closes #2032
1 parent 60dbddf commit 262961c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
emitted in source order as much as possible, instead of always being emitted
55
after the CSS of all module dependencies.
66

7+
### JavaScript API
8+
9+
* Produce a better error message when an environment that supports some Node.js
10+
APIs loads the browser entrypoint but attempts to access the filesystem.
11+
712
### Embedded Sass
813

914
* Fix a bug where nested relative `@imports` failed to load when using the

lib/src/io/node.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ bool get isMacOS => process?.platform == 'darwin';
230230

231231
bool get isJS => true;
232232

233-
bool get isNode => process != null;
233+
/// The fs module object, used to check whether this has been loaded as Node.
234+
///
235+
/// It's safest to check for a library we load in manually rather than one
236+
/// that's ambiently available so that we don't get into a weird state in
237+
/// environments like VS Code that support some Node.js libraries but don't load
238+
/// Node.js entrypoints for dependencies.
239+
@JS('fs')
240+
external final Object? _fsNullable;
241+
242+
bool get isNode => _fsNullable != null;
234243

235244
bool get isBrowser => isJS && !isNode;
236245

0 commit comments

Comments
 (0)