Skip to content

Commit cd54b07

Browse files
authored
Improve error message if sass fails to compile (#4954)
Sass errors shall now show a callstack of what triggered the error
1 parent cbc6e54 commit cd54b07

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

UNRELEASED.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Use [the changelog guidelines](/documentation/Versioning%20and%20changelog.md) t
1717

1818
### Development workflow
1919

20+
- Improve error logging in the event of sass errors. ([#4954](https://github.com/Shopify/polaris-react/pull/4954))
21+
2022
### Dependency upgrades
2123

2224
### Code quality

config/rollup/plugin-styles.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path');
2-
const {promisify} = require('util');
32

43
const {createFilter} = require('@rollup/pluginutils');
54
const nodeSass = require('node-sass');
@@ -22,8 +21,6 @@ module.exports.styles = function styles({
2221

2322
const filter = createFilter(include, exclude);
2423

25-
const renderSass = promisify(nodeSass.render);
26-
2724
const styleProcessor = postcss([
2825
cssModules({
2926
...modules,
@@ -148,11 +145,19 @@ module.exports.styles = function styles({
148145
return null;
149146
}
150147

151-
const sassOutput = await renderSass({
152-
data: source,
153-
outputStyle: 'compact',
154-
includePaths: [path.dirname(id)],
155-
}).then((result) => result.css.toString());
148+
let sassOutput;
149+
try {
150+
sassOutput = nodeSass
151+
.renderSync({
152+
data: source,
153+
file: id,
154+
outputStyle: 'compact',
155+
includePaths: [path.dirname(id)],
156+
})
157+
.css.toString();
158+
} catch (err) {
159+
throw new Error(err.formatted);
160+
}
156161

157162
const postCssOutput = await styleProcessor
158163
.process(sassOutput, {from: id})

0 commit comments

Comments
 (0)