Unable to build docs with 2.x (`Cannot read properties of null`)
Describe the bug
After updating @redocly/cli from 1.34.4 to 2.0.2 I'm unable to build API documentation
To Reproduce Steps to reproduce the behavior:
- Run this command:
npx redocly build-docs openapi.yaml - See error
Prerendering docs Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem. TypeError: Cannot read properties of null (reading 'useRef')
Expected behavior
Redocly 2.0.2 should build documentation, just like 1.34.4 does
OpenAPI description
I'm aware that this issue may be related to the specific openapi.yaml file, however I'd prefer to not share it
Redocly Version(s)
2.0.2
Node.js Version(s)
22.15.0
OS, environment
Windows
Additional context
None
It's likely related to some dependencies combination. Do you use a specific version of React in your project? Or other dependencies that use React? Also, what package manager you use? Another possible issue might be with the NPX cache -- could you clean it? You can also try installing Redocly CLI globally instead on using NPX.
I'm not using React in this project, but I'm using [email protected], which uses react and react-dom in version 18.3.1 as a nested dependency
The @redocly/[email protected] uses react and react-dom in version 19.1.1 and issue doesn't come up
Have you tried installing Redocly CLI globally or as a project dependency? Curious if that could resolve the issue.
When I install package globally with npm --global install @redocly/cli, there is no issue and docs are built without an error
Then I assume it's an npx caching issue. Could you check if cleaning the cache resolves the issue?
I've run
npm cache clean --force
npx clear-npx-cache
but that didn't help.
This is the output of running npm ls react:
[email protected] D:\localhost\app
+-- @redocly/[email protected]
| +-- [email protected]
| | `-- [email protected] deduped
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | | +-- [email protected] deduped
| | | | `-- [email protected]
| | | | `-- [email protected] deduped
| | | `-- [email protected]
| | +-- [email protected]
| | | `-- [email protected] deduped
| | `-- [email protected] deduped
| `-- [email protected]
| `-- [email protected] deduped
`-- [email protected]
+-- @tapjs/[email protected]
| `-- [email protected]
| `-- [email protected]
| +-- [email protected]
| | `-- [email protected] deduped
| `-- [email protected] deduped
`-- @tapjs/[email protected]
`-- @tapjs/[email protected]
+-- [email protected]
| +-- [email protected]
| | `-- [email protected] deduped
| `-- [email protected] deduped
`-- [email protected] deduped
Actually the issue is not related to version 2.x
When I force using react@^18.0.0, I can build docs.
npm install --save-dev react@^18 react-dom@^18
npm dedupe
or use this in package.json:
{
"overrides": {
"@redocly/cli": {
"react": "<19.0.0",
"react-dom": "<19.0.0"
}
},
}
Whenever @redocly/cli uses [email protected], the problem comes back
So my issue seems to be a related to Redocly/redocly-cli#1824
npm decided to bump my react version when I updated @redocly/cli to v2, now that it apparently supports react v19
Hi, @piotr-cz could you add a minimal reproducible example?
@AlexVarchuk
The issue may be related to my openapi.yaml schema + @redocly/cli + react v19.
Maybe it would be reproducible on project that has both @redocly/cli and tap dependencies