osrm-backend
osrm-backend copied to clipboard
Docbox HTML build fails due to ESM/CommonJS conflict
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:
- OSRM's package.json has "type": "module" (added in #7227, #7230)
- Docbox uses CommonJS with require() statements
- 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)