Home > Blockchain >  How to get npm to install a single package?
How to get npm to install a single package?

Time:04-30

I have downloaded an npm project, and npm install fails with a bunch of dependency errors. In an attempt to find the problem, I've tried installing each dependency individually with, e.g., npm install react, but the command ignores the single argument and instead gives the same errors as trying to install the entire project. In desperation I tried the example from https://docs.npmjs.com/cli/v8/commands/npm-install: 'npm install sax`, where sax has nothing to do with the project, and it still fails.

package.json is:

{
  "name": "graphiql-explorer-example",
  "homepage": "https://onegraph.github.io/graphiql-explorer-example",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "graphiql": "^0.12.0",
    "graphql": "^14.1.1",
    "graphiql-explorer": "^0.6.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "2.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "flow": "flow",
    "deploy": "gh-pages -d build",
    "predeploy": "yarn build",
    "prettier": "prettier --write \"src/**/*.js\" \"docs/**/*.md\" README.md"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "flow-bin": "^0.91.0",
    "gh-pages": "^2.0.1"
  },
  "description": "Example usage of [OneGraph](https://www.onegraph.com)'s open source [GraphiQL explorer](https://github.com/OneGraph/graphiql-explorer).",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git https://github.com/OneGraph/graphiql-explorer-example.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/OneGraph/graphiql-explorer-example/issues"
  }
}

The error messages are:

   > npm install react

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/graphql
npm ERR!   graphql@"^14.1.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0" from [email protected]
npm ERR! node_modules/graphiql
npm ERR!   graphiql@"^0.12.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

The log file (excluding a pile of "timing" and "silly" messages) is:


1 info using [email protected]
2 info using [email protected]

22 verbose title npm install sax
23 verbose argv "install" "sax"

41 http fetch GET 200 https://registry.npmjs.org/graphiql 144ms (cache revalidated)

43 http fetch GET 200 https://registry.npmjs.org/graphql 47ms (cache revalidated)

47 verbose stack Error: unable to resolve dependency tree

As you can see, npm parses the "sax" argument correctly on line 23, but then ignores it and tries to install graphiql instead.

How can I get npm to install a single package, such as the latest version of react, instead of trying to install all of the dependencies for graphiql-explorer?

CodePudding user response:

There is a fix for running the npm install command.

$ npm install

According to your error message when running the installation command:

npm ERR! ERESOLVE unable to resolve dependency tree

It states that some dependencies are incompatible with others. To fix this, you need to run the installation command with the following flag.

$ npm install --legacy-peer-deps

This should resolve the issue of the dependencies being incompatible with each other.


In conclusion, the issue was that the dependencies were incompatible with each other. However, there is a fix!

$ npm install --legacy-peer-deps

CodePudding user response:

the problem here is the peer dependencies of "sax"

there are some ways to avoid checking peer dependency.

Method 1

npm install <package name> --force

or

npm install <package name> --legacy-peer-deps

but it is not recommended,

Adding --legacy-peer-deps to your npm installation will bypass peerDependency auto-installation, but this may result in conflicts due to potentially breaking changes

try to resove conflicts manually, by getting the peer dependency details using

npm info name-of-module peerDependencies

for more information refer: What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?

  • Related