Create-react-app: react and react-dom dependencies should have caret range

Created on 27 Feb 2017  路  9Comments  路  Source: facebook/create-react-app

I think https://github.com/facebookincubator/create-react-app/pull/1253 made it so that react and react-dom are also installed with exact range:

  "dependencies": {
    "react": "15.4.2",
    "react-dom": "15.4.2"
  },
  "devDependencies": {
    "react-scripts": "0.9.2"
  },

This is not right. We want to pin react-scripts but leave react and react-dom unpinned:

  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "devDependencies": {
    "react-scripts": "0.9.2"
  },

The easiest way to do it would probably be to remove the exact flag from the installation script in packages/create-react-app/index.js, and instead pin react-scripts to a specific version in the same function that moves react-scripts to devDependencies (also in that file).

bug

Most helpful comment

THX that will be a perfect spot. Try to formulate a PR.

All 9 comments

@gaearon it is kinda wired.
Initializing a project with create-react-app will install the dependencies with exact flag which was introduced with #1253
BUT
there also exists an init script (https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/scripts/init.js) which will install the dependencies without the exact flag. Is that init script needed at all any more?

my suggestion would be as you already mentioned to remove the exact flag and pin react-scripts version AND remove the code path in the init.js

The init script only does this for backwards compatibility with older global CLIs. It is still necessary because we want older CLIs to keep working.

thx for clearing that up. One additional question, there exists some mechanism to install additional dependencies listed in a templates.dependeny.json file That mechanism is obsolete?

No, that that code is used for our kitchensink e2e.

ok :) lots to learn here

Tried out some variants with installing different versions with npm and it seems that it is not possible to install with different modes during an single install. The dependecies will be downloaded and installed with the correct version pattern, but the dependencies in the package.json will all get the same version range.

e.g.

npm install react@^15.0.0 react-dom@^15.0.0 [email protected] --save
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-scripts": "^0.9.1"
  }

npm install react@^15.0.0 react-dom@^15.0.0 [email protected] --save --save-exact
  "dependencies": {
    "react": "15.4.2",
    "react-dom": "15.4.2",
    "react-scripts": "0.9.1"
  }

One way to solve that would be to patch the package.json upfront and afterwards trigger an install.

Yes, we already patch up package.json after install so I just suggest adding an extra character there.

THX that will be a perfect spot. Try to formulate a PR.

Fixed in #1669. Thanks @johann-sonntagbauer!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  路  3Comments

fson picture fson  路  3Comments

oltsa picture oltsa  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

rdamian3 picture rdamian3  路  3Comments