mobx icon indicating copy to clipboard operation
mobx copied to clipboard

mobx-react-lite does not specify `react-dom` nor `react-native` as it's peer dependencies

Open clentfort opened this issue 1 year ago • 0 comments

Intended outcome:

npm install puts react-dom into the right directory so that mobx-react-lite can find it.

Actual outcome:

react-dom might be placed nested into the node_modules of another node_module so that if mobx-react-lite is not right next to react-dom it can not be found.

How to reproduce the issue:

tl;dr

  1. Clone https://github.com/clentfort/mobx-react-lite-npm-peer-deps/tree/main
  2. Run npm exec redocly, see Error: Cannot find module 'react-dom' error.

I ran into this issue when trying to use a package that depends on mobx-react-lite (namely @redocly/cli). They have correctly added react-dom as a dependencies in their package.json. However, with a second dependency in play (cdktf-cli) running npm install will put react-dom into node_modules/@redocly/cli/node_modules/react-dom while mobx-react-lite ends up in node_modules/mobx-react-lite. With this node_modules layout mobx-react-lite can't find react-dom. I think mobx-react-lite needs to add react-dom to it's peerDependencies. It is already present in peerDependenciesMeta and flagged as optional, but that doesn't tell npm that react-dom is an actual peerDependency. It's just meta information about a non-exisiting peerDependency.

Versions

mobx-react-lite: 3.4.3 npm: 10.4.0 node: v20.10.0

clentfort avatar Jun 04 '24 09:06 clentfort