facebook/create-react-app

Create-react-app overrides dependencies in my custom react-scripts template

just-boris opened this issue · 6 comments

I am maintaining fork with a custom react-scripts package, which is based on Preact.
After the change, #1253 has been released the create-react-app command always installs the fixed set of packages do not use package.json from template folder anymore.

Sorry that I did not report it before because usually the update for global command create-react-app is not required and I had stuck at some old version. Recently I have got a report from users, just-boris#17 about that problem.
As a workaround, I have recommended installing preact manually, but it doesn't seem like a good solution.

Can I ask to change the behavior and pick up dependencies from project template folder instead of the hard-coded list with react and react-dom?

The issue is that reading it from package.json if only possible if that package.json is available immediately. However it's not (we fetch a fresh one).

Old versions used to run two installs: first for react-scripts and then for react and react-dom. But this is significantly slower than doing them all at the same time.

I’m open to suggestions for fixing this, but not at the expense of the install time for most users.

could there be a postInstall hook (maybe read it from the template package.json)? In this case that script could uninstall/install the needed packages...

Other option is to run npm i again if using an external template.

I think that if you need it to install something other than React, you might as well use a forked global package (since technically it doesn’t “create React app” anymore). So I’ll close this, but I can take a PR that runs npm install in react-scripts/init.js if some deps are missing.

Sure! So far I have got used to live with the fact, that I need to replace React->Preact manually.

An update here.

Some time before, CRA introduced newer react-error-overlay, that explicitly declares dependency from React. It means that preact-compat is not an optional, but must have. Currently, I am considering publishing fork of create-react-app package too, that will be installing the proper dependencies.

From the good news: error overlay works with Preact very well, giving me a better development experience without any issues along the way.

Timer commented

FYI: The next version of the overlay will be bundled and you will not need to worry about React compat.