Create-react-app: Automatically install dependencies on yarn start?

Created on 15 Jan 2018  路  5Comments  路  Source: facebook/create-react-app

Developers less familiar with modern JavaScript likely have trouble understanding why an error message like this comes up after running yarn start:

image

Would create-react-app benefit from adding a check on yarn start that ensures the latest dependencies are already installed?

proposal

Most helpful comment

I think we should improve this message. We already parse it so might as well add some friendly instructions.

I don鈥檛 think automatic installation is something we鈥檇 want to pursue. There are many details that are easy to get wrong: npm and yarn can break each other鈥檚 trees (and we don鈥檛 know which one the user used last), the dependency may still be missing in package.json and we might install a wrong version, there might be a typo so installing won鈥檛 help, etc.

With that in mind would you like to work on brainstorming how to improve this message for the most common cases?

All 5 comments

I think we should improve this message. We already parse it so might as well add some friendly instructions.

I don鈥檛 think automatic installation is something we鈥檇 want to pursue. There are many details that are easy to get wrong: npm and yarn can break each other鈥檚 trees (and we don鈥檛 know which one the user used last), the dependency may still be missing in package.json and we might install a wrong version, there might be a typo so installing won鈥檛 help, etc.

With that in mind would you like to work on brainstorming how to improve this message for the most common cases?

My _guess_ for the most common cases are:

  1. The developer forgot to run yarn install (or npm install) after the dependencies changed (e.g. after a git pull)
  2. The developer had a typo in the import path
  3. The developer typed import Foo, saved, and forgot to run yarn install
  4. It's a dependency of a dependency and the dependency requiring it assumed the package using it would have installed the child dependency (most complicated case)

We could show TLDR instructions for fixing all of these cases (which would link to a longer article potentially with commenting allowed), and then use some heuristics for ordering which one appears at the top.

It's probably much more complicated than this, but example heuristics:

  • If it's the first build that fails, yarn.lock was modified sooner than node_modules was modified, and the import is to a file doesn't exist in the project, we would suggest the developer run yarn install at the top of the instructions
  • Maybe we could have a "Did you mean?" like what Rails does?[0]
  • The file importing the missing dependency is in the node_modules folder and the node_modules folder was last updated before yarn.lock?

[0]:

[3] pry(main)> Order.new.profil
NoMethodError: undefined method `profil' for #<Order:0x007fbc2b152f68>
Did you mean?  profile
               profile=
               profile?

Personally, I'd go with something simpler like looking up the missing module in package.json and maybe in node_modules as well; if it is not found print something like module "foo" was not found. Please install it with npm (npm install --save foo) or yarn (yarn add foo).

If you ask me I would stick to option to show message but not install dependencies.
Side-effects are always tricky to maintain.

Another thing is this could be a local file and not a module. If you use basePath in a jsconfig (or ts) to make importing from other files in your app easier, then trying to install something wont help. In this case its most likely a typo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akctba picture akctba  路  80Comments

rovansteen picture rovansteen  路  192Comments

Timer picture Timer  路  144Comments

daviseford picture daviseford  路  108Comments

benneq picture benneq  路  99Comments