Skip to content

Docbox HTML build fails due to ESM/CommonJS conflict #7293

@afarber

Description

@afarber

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 Replace custom flatbuffers.cjs with npm package #7227, Convert scripts from CommonJS to modern ESM format #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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions