Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
markdownlint
✓ import markdownlint from 'markdownlint'
✗ const markdownlint = require('markdownlint')
Package is ESM-only since v0.34.0. Use import statement.
lint
✓ import { lint } from 'markdownlint'
Main function exported as named export. Also available as default import.
LintResults
✓ import type { LintResults } from 'markdownlint'
✗ import { LintResults } from 'markdownlint'
LintResults is a TypeScript type, not a runtime value. Import using 'import type'.
markdownlint.sync
✓ import { lintSync } from 'markdownlint'
✗ const { sync } = require('markdownlint')
Synchronous linting is available as a separate named export lintSync since v0.26.0.
Lint a Markdown file with custom configuration and log errors.
import { lint } from 'markdownlint';
import { readFileSync } from 'fs';
const options = {
strings: {
'example.md': readFileSync('example.md', 'utf8'),
},
config: {
default: true,
MD013: { line_length: 80 },
},
};
lint(options, (err, results) => {
if (err) {
console.error(err);
return;
}
for (const file in results) {
const errors = results[file];
errors.forEach((error) => {
console.log(`${file}:${error.lineNumber}: ${error.ruleName} - ${error.ruleDescription}`);
});
}
});
Debug
Known issues
breakingESM-only since v0.34.0, synchronous API removed in v0.26.0fixUse import syntax instead of require(). Use lintSync named export for synchronous usage.
affects: >=0.34.0
deprecatedThe markdownlint.sync function is deprecated since v0.26.0fixUse the lintSync named export instead.
affects: >=0.26.0 <0.34.0
gotchaConfiguration files (like .markdownlint.json) are not automatically loaded when using the API programmaticallyfixManually load and pass the config option object to the lint function.
affects: all
gotchaRule MD024 (multiple headings with same content) by default only checks siblings, not all headingsfixSet allow_different_nesting: false in config to check all headings.
affects: all
Errors
Common errors & fixes
Cannot find module 'markdownlint'
Package not installed or used with require() in ESM-only version
fixInstall with npm: npm install markdownlint --save-dev. Use import statement instead of require().
TypeError: markdownlint.sync is not a function
Using deprecated synchronous API, or importing wrong shape
fixUse import { lintSync } from 'markdownlint' instead of markdownlint.sync. Invalid configuration: 'default' must be a boolean
Setting config.default to a non-boolean value like 'true' (string) or an object
fixSet config.default as a boolean true or false, not a string. Example: default: true
Error: Cannot find module 'micromark'
markdownlint has a peer dependency on micromark that is missing
fixInstall micromark as a dependency: npm install micromark
Audit
Dependencies
micromarkrequiredCore parsing engine for Markdown/CommonMark