Skip to content

package.json misconfigured #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andrewl913 opened this issue Apr 11, 2019 · 9 comments · May be fixed by #91 or #152
Open

package.json misconfigured #75

andrewl913 opened this issue Apr 11, 2019 · 9 comments · May be fixed by #91 or #152

Comments

@andrewl913
Copy link

Looks like react and reace-dom is not only a dependency but also a peer dependency. This can cause issues for those using mono repo workflows such as lerna or yarn workspaces..

Should remove the dependencies and place them in devDependencies

@sirajalam049
Copy link
Contributor

dependencies are required to run, devDependencies only to develop, e.g.: unit tests, CoffeeScript to Javascript transpilation, minification, ...

React is a dependency because it is included in the final build.

More Details:
https://stackoverflow.com/a/48861985/5132337

@andrewl913
Copy link
Author

andrewl913 commented Jul 31, 2019

Sorry for the late reply

This is incorrect.

For reusable components:

Put a react dependency in both peerDependencies and devDependencies.
devDependencies ensures React will be installed when you run npm install while developing your component, or when running tests on Travis or similar.

Putting react in dependencies will cause multiple versions of React to be installed if somebody uses your component but has a different version of React in their own package.json - having multiple versions of React not only bloats the build, but also causes errors when different versions try to interact.

https://stackoverflow.com/questions/30451556/what-is-the-correct-way-of-adding-a-dependency-to-react-in-your-package-json-for

Also imperical proof from libraries already doing this

styled-components: https://github.com/styled-components/styled-components/blob/master/packages/styled-components/package.json

material-ui: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/package.json

formik: https://github.com/jaredpalmer/formik/blob/master/package.json

@andrewl913
Copy link
Author

For this reason alone we had to ditch this library and use our own.

@mlunoe
Copy link

mlunoe commented Oct 16, 2019

I am facing the same issue. Is there an update on this?

@gbhasha
Copy link

gbhasha commented Feb 14, 2020

me too facing same issue.

Having multiple versions of React not only bloats the build, but also causes errors when different versions try to interact. We are using latest react version (16.12.0) with hooks support, but this library causes some error due to different versions of react installed.

Kindly move the react and react-dom from dependencies to devDependencies.

To add to @andrewl913 list, another popular library which doing this.

react-dates (by airbnb) - https://github.com/airbnb/react-dates/blob/master/package.json

react-accessible-accordion - https://github.com/springload/react-accessible-accordion/blob/master/package.json

react-google-maps - https://github.com/tomchentw/react-google-maps/blob/master/package.json

react-id-swiper - https://github.com/kidjp85/react-id-swiper/blob/master/package.json

@gbhasha
Copy link

gbhasha commented Feb 14, 2020

https://stackoverflow.com/a/48861985/5132337

This logic applies to react applications(projects). Not for reusable components.

This library is a reusable component used on other react projects. So it make sense to move the react to devDependency and inform the consumer of the library through peerDependency and avoid bloating the final build having multiple versions of react.

In the same SO thread look at another answer - https://stackoverflow.com/questions/48861868/why-react-should-usually-be-a-prod-dependency-and-not-dev-dependency/48861985#48861985

React could very well be listed as a peer dependency is some of the popuar libraries. This is because we assume that all projects that are going to use this library are going to have React installed. Like consider the case of react-bootstrap. It can only be run in react projects, so we include react as peer dependency reducing the overhead of installing it.

https://github.com/react-bootstrap/react-bootstrap/blob/master/package.json

gbhasha added a commit to gbhasha/react-code-input that referenced this issue Feb 14, 2020
@gbhasha gbhasha linked a pull request Feb 14, 2020 that will close this issue
@acusti
Copy link

acusti commented Oct 15, 2021

i removed the direct react + react-dom dependency and kept them in peerDependencies in #152. it isn’t necessary to have them in devDependencies because @storybook/react takes care of installing react and building the environment on npm start already. i also fixed a handful of other issues and published the result to NPM if anyone wants to give it a try:

npm i @acusti/react-code-input
# or
yarn add @acusti/react-code-input

@giannif
Copy link

giannif commented Jun 6, 2022

@acusti any chance of #152 getting merged and released?

@austinbiggs
Copy link

@acusti any chance of #152 getting merged and released?

Bump! Is there any chance that this will be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants