简体   繁体   中英

NPM installing Dependencies from package.json

Im a bit confused. On my laptop, as I built up my project, my package.json got populated with dependencies as I installed them.

It looks like this:

"main": "webpack.config.js",
  "dependencies": {
    "immutable": "^3.7.6",
    "react": "^0.14.8",
    "react-dom": "^0.14.8",
    "react-redux": "^4.4.2",
    "redux": "^3.4.0"
  },
  "devDependencies": {
    "babel-core": "^6.7.6",
    "babel-loader": "^6.2.4",
    "babel-polyfill": "^6.7.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-react-hmre": "^1.1.1",
    "css-loader": "^0.23.1",
    "eslint": "^2.7.0",
    "eslint-loader": "^1.3.0",
    "eslint-plugin-react": "^4.3.0",
    "postcss-loader": "^0.8.2",
    "style-loader": "^0.13.0",
    "stylelint": "^4.5.1",
    "webpack": "^1.12.15",
    "webpack-dev-server": "^1.14.1",
    "webpack-merge": "^0.7.3"
  },

Now, on my new system, pulled the repo & was under the impression that all I have to call is npm install & npm would read package.json & download all the dependencies and their specified versions. That didnt happen.

So, my question is, how do we correctly, install all of these dependencies onto a new system.

Would it be a matter of running npm i --save [all the dependencies]

& npm i --save-dev [all the dev dependencies]

Also, how would the version number be resolved if I do the above? I mean, package.json has the versions specified while running the above two commands would download the latest versions of each package.

Many thanks,

If you want to install the latest module versions meet the version requirements, you should use the command:

npm i

In that case, for immutable module, for example, will be installed the latest 3.x version.

But if you want to install the same versions as on your first development pc, you need too do the following:

npm shrinkwrap # run this command on first pc 
npm i          # run this command on a new pc

All you have to call is npm install, it will download the most recent major versions (^ caret range syntax) listed in dependencies and devDependencies

https://docs.npmjs.com/cli/install

To install a specific version, remove the caret eg

"react": "0.14.8",

You can use 'npm shrinkwrap' to lock down the versions of a package's dependencies -- creates a file npm-shrinkwrap.json containing the exact package versions in the entire hierarchy

https://docs.npmjs.com/cli/shrinkwrap


package.json interactive guide http://browsenpm.org/package.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM