redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

ReferenceError: React is not defined

Open Denny-g6labs opened this issue 9 months ago • 25 comments

Describe the bug

The following error appears since today: ReferenceError: React is not defined. We install the latest version globally and use it in our GitHub Action for the following command: npx redocly bundle ${dest_folder}/swagger.yaml -o ${dest_folder}/swagger-prepared.json

To Reproduce

  1. npm install -g @redocly/cli@latest
  2. redocly --help

Expected behavior

No error, exit code 0.

Logs

ReferenceError: React is not defined
    at Object.<anonymous> (/usr/local/lib/node_modules/@redocly/cli/node_modules/styled-components/dist/styled-components.cjs.js:1:860)
    at Module._compile (node:internal/modules/cjs/loader:1521:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at Module.require (node:internal/modules/cjs/loader:1289:19)
    at require (node:internal/modules/helpers:182:18)
    at /usr/local/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:2:109941
    at /usr/local/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:1831:3804
    at /usr/local/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:1831:3809

Node.js v20.20.0

OpenAPI description

# See https://redocly.com/docs/cli/configuration/

extends:
  - recommended

rules:
  # Currently we don't have a license for our APIs
  info-license: "off"

theme:
  openapi:
    generateCodeSamples:
      languages:
        - lang: curl
        - lang: Node.js
        - lang: Python

Redocly version(s)

2.18.2

Node.js version(s)

v20.20.0

OS, environment

Linux, Max, GitHub ubuntu-latest

Additional context

It worked the last 3 years until today (can't say if it worked the last 2 days, but definitely before).

Denny-g6labs avatar Feb 18 '26 14:02 Denny-g6labs

same exact issue here. Was working fine up until last night and started breaking with the same error today.

mscrivo avatar Feb 18 '26 14:02 mscrivo

There's some issue on a dependency's side (most likely with styled-components). We're already investigating it.

tatomyr avatar Feb 18 '26 14:02 tatomyr

Same issue here!

fermolinuevo avatar Feb 18 '26 14:02 fermolinuevo

same here

tanguc avatar Feb 18 '26 14:02 tanguc

https://github.com/styled-components/styled-components/issues/5667

swistakm avatar Feb 18 '26 14:02 swistakm

@tatomyr thanks! curious though, this has happened a couple times in recent months. Shouldn't redocly-cli pin its deps to avoid surprises like this?

mscrivo avatar Feb 18 '26 14:02 mscrivo

same here

ankitTelnyx avatar Feb 18 '26 14:02 ankitTelnyx

@mscrivo yeah, this is one of the options.

tatomyr avatar Feb 18 '26 14:02 tatomyr

Hey,

you can add the override for styled-components to avoid the error until this is figured out.

e.g.

  "devDependencies": {
    "@redocly/cli": "^2.0.0"
  },
  "overrides": {
    "styled-components": "6.1.19"
  },

Adrians-G avatar Feb 18 '26 14:02 Adrians-G

Hey,

you can add the override for styled-components to avoid the error until this is figured out.

e.g.

  "devDependencies": {
    "@redocly/cli": "^2.0.0"
  },
  "overrides": {
    "styled-components": "6.1.19"
  },

Doesn't work when running it in the command line though

Spence1115 avatar Feb 18 '26 14:02 Spence1115

The fix is underway, folks. Tests are running...

tatomyr avatar Feb 18 '26 14:02 tatomyr

We’re seeing the same issue across all our CI/CD pipelines. Thank you for addressing this so quickly.

xIceFox avatar Feb 18 '26 14:02 xIceFox

Released the fix to NPM.

tatomyr avatar Feb 18 '26 14:02 tatomyr

I still got this error:

node:internal/modules/run_main:123
    triggerUncaughtException(
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/build/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/react-dom/server' imported from /build/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@redocly/cli/lib/commands/build-docs/utils.js
Did you mean to import "react-dom/server.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:859:10)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:731:20)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:310:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:182:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///build/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/react-dom/server'

chiefbrain avatar Feb 18 '26 15:02 chiefbrain

@tatomyr We see same problem on latest v1 (1.34.6). Is there any chance to also push a v1 fix? It broke on an automation on our side and we can't easily upgrade to v2. At least not that quickly.

pboos avatar Feb 18 '26 15:02 pboos

Working on the fix for V1.

tatomyr avatar Feb 18 '26 15:02 tatomyr

Thanks for fixing this too fast!!!

fermolinuevo avatar Feb 18 '26 15:02 fermolinuevo

fixed for v1 too, please let as know if you still have an issue

vadyvas avatar Feb 18 '26 16:02 vadyvas

@chiefbrain could you please provide a little bit more details about your issue ?

vadyvas avatar Feb 18 '26 16:02 vadyvas

@vadyvas Can you also apply to 1.19.0? I'm having the same issue

peterson-tubini avatar Feb 18 '26 17:02 peterson-tubini