Description
Running npm start in the Swagger UI repo fails on Node 20+ with this error:
TypeError: require(...) is not a function
at [eval]:1:16
This happens because the open package is now ESM-only, and using it via require() in a CommonJS script is no longer supported.
Problematic script is
In the current package.json, the script is:
"open-static": "node -e "require('open')('http://localhost:3002')\""
This fails on modern Node versions.
Fix:
Replace the script with a more compatible version using npx:
"open-static": "npx open-cli http://localhost:3002"
Above line is included in package.json , Now swagger-ui is starting on node 20+ versions also
And optionally add open-cli as a dev dependency:
npm install --save-dev open-cli
Note: npx will work even without installing open-cli locally, but for CI/stability, it’s better to include it in devDependencies.