#2006·jsdoc

Cannot load a javascript config file from an ESM project

Author: alxroyerCreated Aug 17, 2022Updated Mar 26, 2026

When the project is defined as ESM, and the jsdoc configuration file is defined as a javascript file, jsdoc fails at loading it with a "Cannot parse the config file" error.

Input code

Inside 'package.json' (ESM by default):

json
{
  "type": "module",
}

JSDoc configuration

'tools/conf/jsdoc.js':

javascript
"use strict";

// CommonJS module import.
const path = require('path');

module.exports = {
  // Whatever...
};

JSDoc debug output

Execution:

bash
$ ./node_modules/.bin/jsdoc --configure ./tools/conf/jsdoc.js
Cannot parse the config file ./tools/conf/jsdoc.js: Error [ERR_REQUIRE_ESM]: require() of ES Module ...\tools\conf\jsdoc.js from ...\node_modules\jsdoc\cli.js not supported.
jsdoc.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename jsdoc.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in ...\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Exiting JSDoc because an error occurred. See the previous log messages for details.
There are no input files to process.

Expected behavior

The configuration file shall load successfully, either as CommonJS or ESM.

Current behavior

Jsdoc fails at loading the javascript configuration file with a "Cannot parse the config file" error.

Your environment

Software Version
JSDoc 3.6.7
Node.js v16.13.2
npm 8.1.2
Operating system Windows + Git bash