Skip to content

Bug: npm start fails due to ESM open package in Node 20+ #10516

Open
@Ashutoshyadav01

Description

@Ashutoshyadav01

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions