facebook/create-react-app

Changes to node_modules should trigger recompilation

gaearon opened this issue · 6 comments

  1. Add import 'react-router' to index.js
  2. See module not found error
  3. npm install react-router
  4. Still see module not found error
  5. Press “save” in index.js
  6. Now it compiled successfully!

Steps 4 and 5 should not be there. We should find a way to tell webpack that node_modules have changed, and it’s worth trying to recompile.

Ideally we should not have situations where user is forced to stop the bundler and run npm start again. I remember having such issues when switching branches. Hopefully fixing the above use case should be enough, but if you’re familiar with other cases where a restart is required, please write in this thread.

Do you mean npm install react-router --save? I suspect there are performance issues with watching the whole node_modules tree - React Native runs into that - but just watching package.json seems like it should be efficient. But it wouldn't catch it if you just npm install react-router.

@lacker yes you have to restart when you do npm install react-router --save which like you said wouldn't be an issue to watch the package.json.

While I think installing a node module without --save it still seems like a janky experience regardless. Perhaps there is a way you can check if webpack is throwing aModule not found error and then check the node_modules rather than having to watch them directly?

What about using this? https://github.com/ericclemmons/npm-install-webpack-plugin I think that solves our problem.

insin commented

@mxstbr beat me to it, npm-install-webpack-plugin is DX gold /cc @ericclemmons

That's a pretty slick plugin, #212 is an attempt at implementing it.

taion commented

I have a vague recollection that this used to "just work" with npm2, but that it stopped working after I upgraded to npm3.

Didn't have a chance to look into that, though.