React-dates: Missing dependency `react-addons-shallow-compare`

Created on 18 Aug 2016  ยท  12Comments  ยท  Source: airbnb/react-dates

Tried pulling this into a project today and I'm getting a build error:

Error: Cannot resolve module 'react-addons-shallow-compare'

Looks like that dependency is used in several of the components, but it's listed as one of the devDependencies in package.json...seems like that needs to be moved to one of the dependencies so it can be installed for use in production. Am I missing something?

Most helpful comment

Is there a way to use the traditional npm install process instead of the custom command? It doesn't seem to line up with other packages out there that just rely on npm install/postinstall etc. I don't have a specific alternative (sorry) but the current process doesn't exactly work 100% with yarn. Thanks for the lib.

All 12 comments

Since react things are singletons, it'd need to be a peer dependency + dev dependency. Thanks for the report!

Ah, actually it's already a peerDependency - run npm ls and you'll see all the missing peer dependencies that this project requires.

I've updated the readme with an installation command that will grab all the peer deps for you.

Is there a way to use the traditional npm install process instead of the custom command? It doesn't seem to line up with other packages out there that just rely on npm install/postinstall etc. I don't have a specific alternative (sorry) but the current process doesn't exactly work 100% with yarn. Thanks for the lib.

@coreylight yarn already has this covered for you ๐Ÿ˜„ https://yarnpkg.com/en/docs/cli/add#toc-yarn-add-peer-p

So I did this:

โšก yarn add react-dates
yarn add v0.15.1
warning [email protected]: Dependency "events" listed in "dependencies" is the name of a built-in module
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
warning Unmet peer dependency "react-addons-shallow-compare@>=0.14".
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”‚  โ””โ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]
โœจ  Done in 10.33s.

Then when I fired up my webpack build again I got this:

ERROR in ./~/react-dates/lib/components/DayPicker.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/corey/Documents/hud/node_modules/react-dates/lib/components
 @ ./~/react-dates/lib/components/DayPicker.js 698:18-57

ERROR in ./~/react-dates/lib/components/CalendarMonthGrid.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/corey/Documents/hud/node_modules/react-dates/lib/components
 @ ./~/react-dates/lib/components/CalendarMonthGrid.js 372:18-57

ERROR in ./~/react-dates/lib/components/CalendarDay.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/corey/Documents/hud/node_modules/react-dates/lib/components
 @ ./~/react-dates/lib/components/CalendarDay.js 354:18-57
Child html-webpack-plugin for "index.html":

Am I missing something?

try yarn add react-dates -P

Seems to cause the same issue.

Removed react-addons-shallow-compare and also react-dates
Then ran this:

โšก yarn add react-dates -P
yarn add v0.15.1
warning [email protected]: Dependency "events" listed in "dependencies" is the name of a built-in module
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
warning Unmet peer dependency "react-addons-shallow-compare@>=0.14".
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]
โœจ  Done in 8.59s.

So, same thing?

For the record, if something works with npm but not with yarn, it's a yarn bug - please file it on their repo.

@coreylight the reason for the fancy install command is because npm doesn't offer an easy way to guarantee you have the right peer deps in your package.json. yarn add -P may indeed offer that, but the command provided should work just fine with npm, after which you can regenerate your yarn.lock file.

It seems as if you just duplicate all the peerdeps into the dependencies in the package.json, it will work great for npm 3+ users. npm 2 users can just run npm dedupe if they want?

npm 2 automatically installs peer deps, but doesn't put them in package.json - which is an error. Peer deps of deps should always be explicitly listed in package.json, which this command achieves in npm 2 and 3+.

@coreylight yeah not working for me either - maybe I misread the docs. I would just follow @ljharb's suggestion for now (install via NPM). Also if you're on a PC I put together a PowerShell command (to help with the peer dependencies install) that's in the comments of this PR here: https://github.com/airbnb/react-dates/pull/107

Was this page helpful?
0 / 5 - 0 ratings

Related issues

swaritkohli picture swaritkohli  ยท  3Comments

cemremengu picture cemremengu  ยท  3Comments

arthurvi picture arthurvi  ยท  3Comments

Jesus-Gonzalez picture Jesus-Gonzalez  ยท  3Comments

AsasinCree picture AsasinCree  ยท  3Comments