Does Stylus have a flag to turn missing imports into errors?
No. The Stylus compiler (the Node.js implementation) treats an unresolved @import as a no-op: it does not emit a warning or error and simply skips the import, which can lead to silent omission of styles.
Why this happens
Stylus was designed to allow optional imports; the parser does not throw when a file cannot be resolved, and there is no compiler option or API switch to change that behavior.
Verification steps you can add to a build pipeline
- Pre-build file-existence check – write a small Node script (or gulp/grunt task) that extracts all
@import paths from your Stylus sources and verifies each resolved path exists against the configured include paths. Fail the build if any are missing.
- Linting rule – use a Stylus-aware linter (e.g.,
stylelint with a custom rule or stylus-lint) that reports unresolved imports.
- Post-build CSS audit – generate source maps and run a CSS audit tool (e.g.,
csslint or stylelint) to detect unexpectedly empty or missing rules; note that this may miss imports that would not affect CSS size.
Example Node verification script
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const srcFiles = glob.sync('src/**/*.styl');
const includePaths = ['src', 'src/components']; // adjust to your stylus --include-path
function extractImports(content) {
const regex = /@import\s+['"]([^'"]+)['"]/g;
const matches = [];
let m;
while ((m = regex.exec(content)) !== null) {
matches.push(m[1]);
}
return matches;
}
let missing = false;
for (const file of srcFiles) {
const content = fs.readFileSync(file, 'utf8');
const imports = extractImports(content);
for (const imp of imports) {
let resolved = false;
for (const base of includePaths) {
const full = path.resolve(base, imp);
if (fs.existsSync(full + '.styl') || fs.existsSync(full)) {
resolved = true;
break;
}
}
if (!resolved) {
console.error(`Missing import: ${imp} in ${file}`);
missing = true;
}
}
}
process.exit(missing ? 1 : 0);
Behavior of wrappers
Wrappers such as stylus-loader for webpack or gulp-stylus delegate to the underlying Stylus compiler, so they exhibit the same silent-skip behavior. No known wrapper adds automatic error reporting for missing imports.