How to fix Error: recursive option not supported in this Node.js version in Node.js

Node.jsBEGINNERMEDIUMUpdated Dec 9, 2025ยท 148 views

This error occurs when using the recursive option with fs.mkdir() or fs.mkdirSync() in an older version of Node.js that does not support this feature. The recursive option was added in Node.js 10.12.0 to create directories recursively with a single command.

Quick fix

Fixes Error: recursive option not supported in this Node.js version

# Check Node.js version
node --version

# Or
node -v
  1. Check your current Node.js version
  2. Upgrade Node.js to a supported version
  3. Update Docker base image if using containers
  4. Update CI/CD pipeline Node.js version
node.js โ€” error
# Check Node.js version
node --version
# Or
node -v
Error: recursive option not supported in this Node.js version

What this error means

This error indicates that your Node.js version does not support the recursive option in the fs.mkdir() or fs.mkdirSync() functions. The recursive option, which creates all missing parent directories automatically, was introduced in Node.js 10.12.0. When you use fs.mkdir(path, { recursive: true }, callback) on an older Node.js version (before 10.12.0), Node.js throws an error because it doesn't recognize the recursive option. This is a version compatibility issue that requires either upgrading your Node.js installation or using an alternative approach to create nested directories. The error typically occurs during: - Building projects that require nested directory creation - Running tools or libraries that depend on the recursive mkdir feature - Using newer code on older Node.js environments (local development vs production server mismatch) - Executing scripts written for newer Node.js versions on legacy systems

Typical symptoms

  • fs.mkdir() or fs.mkdirSync() with recursive option throws an error
  • Error message contains "recursive option not supported"
  • Directory creation fails even though the code looks correct
  • Build or setup scripts fail during directory creation steps
  • Application works on one system but not another (version mismatch)
  • Testing frameworks or build tools fail to initialize properly

Common causes

  1. Running code on Node.js version older than 10.12.0
  2. Production server has an older Node.js version than development environment
  3. Docker image or container uses an outdated Node.js base image
  4. System-installed Node.js is outdated and npm/npx uses that version
  5. CI/CD pipeline configured to use legacy Node.js version
  6. Mismatched .nvmrc or node-version file in project

How to fix "Error: recursive option not supported in this Node.js version"

1Check your current Node.js version

First, verify which version of Node.js you are running:

bash
# Check Node.js version
node --version

# Or
node -v

The recursive option requires Node.js 10.12.0 or later. If your version is older than 10.12.0, you need to upgrade.

2Upgrade Node.js to a supported version

Install a newer version of Node.js that supports the recursive option (10.12.0 or later, but 12.x LTS or newer is recommended):

Using Node Version Manager (nvm) - Linux/macOS:

bash
# Install nvm if not already installed
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Reload shell configuration
source ~/.bashrc

# List available Node.js versions
nvm list-remote

# Install the latest LTS version
nvm install --lts

# Or install a specific version
nvm install 18.0.0

# Set default version
nvm alias default 18.0.0

# Switch to the new version
nvm use 18.0.0

# Verify installation
node --version

Using nvm on Windows (nvm-windows):
1. Download nvm-windows from https://github.com/coreybutler/nvm-windows
2. Run the installer
3. Open PowerShell or CMD and run:

powershell
nvm install 18.0.0
nvm use 18.0.0
node --version

Using Homebrew - macOS:

bash
brew install node
# Or upgrade
brew upgrade node

Using Windows Installer:
1. Visit https://nodejs.org/
2. Download the LTS version
3. Run the installer and follow prompts
4. Restart terminal and verify: node --version

3Update Docker base image if using containers

If running in Docker, update your Dockerfile to use a modern Node.js image:

Before (using outdated version):

dockerfile
FROM node:8
# or
FROM node:9

After (using supported version):

dockerfile
FROM node:18-alpine
# or for more features
FROM node:18-slim
# or latest stable
FROM node:20-alpine

Then rebuild your Docker image:

bash
docker build -t myapp:latest .
docker run myapp:latest

Alpine images are smaller, slim images are medium-sized, and full images include additional tools.

4Update CI/CD pipeline Node.js version

Check and update your continuous integration configuration:

GitHub Actions:

yaml
- uses: actions/setup-node@v3
  with:
    node-version: '18'

GitLab CI:

yaml
image: node:18-alpine

stages:
  - build

build:
  script:
    - npm install
    - npm run build

Travis CI:

yaml
language: node_js
node_js:
  - "18"

Vercel/Netlify:
Check deployment settings in your dashboard and update the Node.js version there.

5Update .nvmrc if using nvm

If your project uses nvm, update the .nvmrc file to specify a compatible version:

bash
# Create or update .nvmrc in your project root
echo "18.0.0" > .nvmrc

# Then developers can use
nvm use
# Or with nvm on first time
nvm install < .nvmrc
nvm use < .nvmrc

This ensures all developers use the same Node.js version.

6Use polyfill approach for legacy environments

If upgrading is not possible, implement a helper function that creates nested directories:

javascript
const fs = require('fs');
const path = require('path');

// Polyfill for older Node.js versions
function mkdirRecursive(dirPath) {
  if (fs.existsSync(dirPath)) {
    return;
  }

  const parentPath = path.dirname(dirPath);
  if (!fs.existsSync(parentPath)) {
    mkdirRecursive(parentPath);
  }

  fs.mkdirSync(dirPath);
}

// Usage
mkdirRecursive('./path/to/nested/dir');

Or use a helper library:

javascript
const mkdirp = require('mkdirp');

mkdirp('./path/to/nested/dir').then(made => {
  console.log('Created', made);
});

Install mkdirp:

bash
npm install mkdirp
7Update all development tools to use correct Node version

Ensure your entire development environment uses the updated Node.js:

bash
# Reinstall global tools
npm install -g npm@latest

# Verify npm version
npm --version

# Clear npm cache
npm cache clean --force

# Reinstall project dependencies
rm -rf node_modules package-lock.json
npm install

# Verify everything works
node --version
npm --version

If using yarn or pnpm:

bash
# For yarn
yarn --version
yarn install

# For pnpm
pnpm --version
pnpm install

Advanced notes

Node.js Version History: The recursive option was added in Node.js 10.12.0 (released September 2018). If you're targeting end-of-life Node.js versions (like Node.js 8 or 9), consider that these versions no longer receive security updates. It's recommended to use active LTS versions: Node.js 18, 20, or newer.

Semantic Versioning in Node.js: Node.js follows semantic versioning. Even-numbered releases (10, 12, 14, 16, 18, 20) become LTS (Long Term Support) and receive 3 years of active support plus 2 years of maintenance. Odd-numbered releases (11, 13, 15, 17, 19) only get 6 months of support and should not be used in production.

fs.promises Alternative: For modern async code, consider using fs.promises instead of callbacks:

javascript
const fs = require('fs').promises;

async function createDirs() {
  await fs.mkdir('./path/to/nested/dir', { recursive: true });
}

createDirs().catch(console.error);

This automatically handles the recursive option and is only available in Node.js 10.13.0+.

Environment Detection: If you must support older versions, detect the feature before using it:

javascript
const semver = require('semver');
const nodeVersion = process.version;

if (semver.gte(nodeVersion, '10.12.0')) {
  fs.mkdirSync(path, { recursive: true });
} else {
  // Use legacy approach
  mkdirRecursive(path);
}

Package.json Engines Field: Specify minimum Node.js version in package.json to prevent installation on incompatible systems:

json
{
  "engines": {
    "node": ">=10.12.0",
    "npm": ">=6.0.0"
  }
}

Frequently asked questions

What does "Error: recursive option not supported in this Node.js version" mean?
mkdirSync() functions. 0. js throws an error because it doesn't recognize the recursive option.
How do I fix "Error: recursive option not supported in this Node.js version"?
This error occurs when using the recursive option with fs.mkdir() or fs.mkdirSync() in an older version of Node.js that does not support this feature. The recursive option was added in Node.js 10.12.0 to create directories recursively with a single command.
What causes "Error: recursive option not supported in this Node.js version"?
Running code on Node.js version older than 10.12.0 Production server has an older Node.js version than development environment Docker image or container uses an outdated Node.js base image
Is the "Error: recursive option not supported in this Node.js version" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading