redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Bundle throws error about missing react-is package missing

Open geertendoornenbal opened this issue 5 years ago • 7 comments

After updating to the latest release candidate (57), we bumped into the issue that it is missing a dependency on react-is. After adding that to our own package.json we are able to bundle again. The weird thing about this is that react-is looks like a testing (dev) dependency.

Please see the following error:

> redoc-cli bundle ../src/schemas/openapi.yaml --options redoc-options.json -o ../deploy/docs/index.html

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'react-is'
Require stack:
- C:\code\wx-routing-api\doc\node_modules\redoc-cli\node_modules\styled-components\dist\styled-components.cjs.js
- C:\code\wx-routing-api\doc\node_modules\redoc-cli\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (C:\code\wx-routing-api\doc\node_modules\redoc-cli\node_modules\styled-components\dist\styled-components.cjs.js:1:145)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\code\\wx-routing-api\\doc\\node_modules\\redoc-cli\\node_modules\\styled-components\\dist\\styled-components.cjs.js',
    'C:\\code\\wx-routing-api\\doc\\node_modules\\redoc-cli\\index.js'
  ]
}

geertendoornenbal avatar Nov 08 '21 08:11 geertendoornenbal

I have this problem too!

millmanorama avatar Nov 08 '21 08:11 millmanorama

Hey,

We use npx with the redoc-cli and we have the same problem in our CI pipelines !

$ npx redoc-cli bundle -o public/api/index.html openapi.json
node:internal/modules/cjs/loader:944
  throw err;
  ^
Error: Cannot find module 'react-is'
Require stack:
- /builds/xxx/building-blocks/api/node_modules/redoc-cli/node_modules/styled-components/dist/styled-components.cjs.js
- /builds/xxx/building-blocks/api/node_modules/redoc-cli/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/builds/xxx/building-blocks/api/node_modules/redoc-cli/node_modules/styled-components/dist/styled-components.cjs.js:1:145)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Module.require (node:internal/modules/cjs/loader:1013:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/builds/xxx/building-blocks/api/node_modules/redoc-cli/node_modules/styled-components/dist/styled-components.cjs.js',
    '/builds/xxx/building-blocks/api/node_modules/redoc-cli/index.js'
  ]
}

xavhoff avatar Nov 16 '21 11:11 xavhoff

I was investigating this due to a sudden build failure in CI, so I'm sharing some thoughts:

react-is is a peerDependency in redoc-cli's lock file.

NPM>=7 installs this dependency implicitly when users install redoc-cli. NPM<7 doesn't.

I think using a lock file version 2 here effectively means redoc-cli should be considered incompatible with NPM<7.

  • One workaround might be to add react-is to redoc-cli's dependencies, so NPM<7 installs it in host packages.
    • This seems like a workaround to me because it will probably break in a similar way in the future with other dependencies.
  • Downgrade the lock file to a version 1 file.
    • I'd expect that if the lock file is generated with NPM 6, that we get a version 1 lock file as well as a warning about a peer dependency being unmet. Which we'd then meet by installing react-is.
    • I don't know what other side-effects this might have, as far as I understand NPM>=7 is backwards compatible though.
    • This probably means dev needs to happen on NPM 6 though because 7 probably automatically upgrades the lock file.
  • Require NPM>7. Possibly in engines.npm?

At least that's how I understand what's happening :sweat_smile: I didn't try to make any of the changes that I suggested above, so it's all based on assumptions.

DavidSchillinger avatar Nov 26 '21 11:11 DavidSchillinger

Thanks for the issue. We'll investigate it. Related to https://github.com/Redocly/redoc/issues/1736

AlexVarchuk avatar Nov 29 '21 11:11 AlexVarchuk

Using the last version of redoc-cli (through npx) is now working ! Thank you guys

xavhoff avatar Dec 22 '21 14:12 xavhoff

Fixes this issue on our side as well! Thanks!

geertendoornenbal avatar Dec 23 '21 16:12 geertendoornenbal

If it happens again. Feel free to reopen the issue.

AlexVarchuk avatar Feb 04 '22 13:02 AlexVarchuk