osrm-backend icon indicating copy to clipboard operation
osrm-backend copied to clipboard

Docbox HTML build fails due to ESM/CommonJS conflict

Open afarber opened this issue 3 weeks ago • 0 comments

Issue

The npm run docs command fails when building the HTML documentation site with docbox:

ReferenceError: require is not defined in ES module scope, you can use import instead

This file is being treated as an ES module because it has a '.js' file extension and 'package.json' contains "type": "module".

This happens because:

  1. OSRM's package.json has "type": "module" (added in #7227, #7230)
  2. Docbox uses CommonJS with require() statements
  3. Babel transpiles docbox source to CommonJS, but Node.js treats .js files as ESM due to the package.json setting

The api.md generation works fine (fixed in #7274), but the HTML site build in build/docs/ fails.

Docbox hasn't been updated since June 2018 and is essentially abandoned. We should probably replace it with a modern alternative like Docsify or Docusaurus.

Steps to reproduce

  • osrm-backend version: current master
  • Run npm ci
  • Run npm run docs
  • Observe error after the babel transpilation step

Specifications

  • docbox version: 1.0.11
  • Node.js: v20+
  • Operating system: any (reproducible on Ubuntu 22.04 in CI and macOS locally)

afarber avatar Dec 06 '25 20:12 afarber