Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
mkdir (async ESM)
✓ import { mkdir } from 'mk-dirs';
✗ import mkdir from 'mk-dirs';
This is the primary asynchronous API for ES Modules. It is a named export, not a default export.
mkdir (async CJS)
✓ const { mkdir } = require('mk-dirs');
✗ const mkdir = require('mk-dirs');
This is the primary asynchronous API for CommonJS environments. Ensure you destructure the 'mkdir' function from the module object.
mkdir (sync ESM)
✓ import { mkdir } from 'mk-dirs/sync';
✗ import { mkdir } from 'mk-dirs';
For synchronous operation, you must import specifically from `mk-dirs/sync`. Importing from the default path will yield the asynchronous API.
Demonstrates asynchronous recursive directory creation using both async/await and Promise chaining, including the use of a custom `cwd` option.
import { mkdir } from 'mk-dirs';
import { resolve } from 'path';
async function createDirectories() {
const baseDir = process.cwd();
console.log(`Current working directory: ${baseDir}`);
// Async/await usage
try {
let output1 = await mkdir('foo/bar/baz');
console.log(`Created directory (async/await): ${output1}`);
// Using `cwd` option
let customCwd = resolve(baseDir, 'temp/custom');
let output2 = await mkdir('alpha/beta', { cwd: customCwd });
console.log(`Created directory with custom cwd: ${output2}`);
} catch (err) {
console.error('Error during async/await mkdir:', err);
}
// Promise chain usage
mkdir('another/path/deeply')
.then(output => {
console.log(`Created directory (Promise chain): ${output}`);
})
.catch(err => {
console.error('Error during Promise chain mkdir:', err);
});
}
createDirectories();
Debug
Known issues
gotchaNative Node.js support for recursive directory creation makes external libraries like mk-dirs potentially redundant for simple use cases. Node.js v10.12.0 and above include `fs.mkdir` and `fs.mkdirSync` with a `{ recursive: true }` option, offering built-in functionality.fixConsider using Node.js's native `fs.promises.mkdir` or `fs.mkdirSync` with `{ recursive: true }` for new projects or when migrating older code, unless `mk-dirs`'s specific features (like the 'cwd' option) are required. affects: >=10.12.0 (Node.js)
gotchaThe synchronous API requires an explicit import path: `mk-dirs/sync`. Importing from the default `mk-dirs` will always provide the asynchronous, Promise-based API.fixTo use the synchronous version, ensure your import statement is `import { mkdir } from 'mk-dirs/sync';` for ESM or `const { mkdir } = require('mk-dirs/sync');` for CommonJS. affects: >=3.0.0
gotchaDirectory permissions (`options.mode`) must be specified in octal format, not decimal. Incorrectly formatted modes can lead to unexpected permissions or errors.fixAlways prefix octal numbers with '0o', e.g., `0o755` instead of `755`. The default is `0o777 & (~process.umask())`.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: (0 , mk_dirs__WEBPACK_IMPORTED_MODULE_0__.mkdir) is not a function
Attempting to call the module object directly, or incorrect destructuring of the named 'mkdir' export in ESM or CJS.
fixFor ESM, ensure you use `import { mkdir } from 'mk-dirs';`. For CommonJS, use `const { mkdir } = require('mk-dirs');`. UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
The `mkdir` function returns a Promise, and its rejection was not handled by an `await` within a `try/catch` block or a `.catch()` method.
fixWrap async calls in a `try...catch` block (`await mkdir(...);`) or chain a `.catch(err => { /* handle error */ })` to the Promise return. Error: EPERM: operation not permitted, mkdir '/path/to/dir'
Insufficient file system permissions for the current user to create directories at the specified path, or an incorrect `mode` option was applied.
fixRun the process with appropriate user permissions, verify the target directory is writable, or ensure the `mode` option is correctly specified in octal format (e.g., `0o777`).
Audit
Dependencies
No dependency data recorded yet.