0

Is it possible to add the specified semver range of the installed package from CLI rather than editing package.json manually?

The following command:

npm i --save-peer react@">= 18" svelte@"*"

results in changes in package.json:

  "peerDependencies": {
    "react": "^18.3.1",
    "svelte": "^4.2.18"
  }

But the required result is to add the exact semver ranges, including a wildcard:

  "peerDependencies": {
    "react": ">= 18",
    "svelte": "*"
  }

The resolved versions (18.3.1 and 4.2.18) should only be mentioned in package-lock.json, not package.json.

1
  • You can use --save-prefix for ~ or ^ and --save-exact for neither, but not for others I don't think. Commented Aug 21, 2024 at 17:49

1 Answer 1

0

This can be achieved with low-level pkg command:

npm pkg set peerDependencies.react=">= 18" peerDependencies.svelte="*" && npm i

Also this may work differently in other package managers, e.g. yarn add is known to be able to add a version as is.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.