Performing a hands-free npm installation with --legacy-peer-deps activated, tailored specifically for an

Let's imagine a scenario where I have a package.json structured like this:

{
  "name": "my-app",
  "version": "0.1.0",
  "dependencies": {
    "@aws-sdk/client-s3": "^3.21.0",
    "@testing-library/react": "^11.2.5",
    "axios": "^0.22.0",
    "credit-card-type": "^8.3.0",
    "csstype": "^3.0.8",
    "dayjs": "^1.10.4",
    "lodash": "^4.17.20",
    "mathjax-full": "^3.2.0",
    "mathjax-react": "^1.0.6",
    "react": "^17.0.2",
  },
  "proxy": "http://localhost:5000",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "jest",
    "eject": "react-scripts eject",
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

The challenge arises when the dependencies mathjax-react and mathjax-full require

react@"^15.0.0 || ^16.0.0"
. Despite successful testing with npm i --force and npm i --legacy-peer-deps, there is a desire to streamline the process without having to use these commands each time new dependencies are installed, especially for the mentioned packages which should be automatically handled during npm i. Exploring options in the .npmrc configuration and related resources did not provide a clear solution. Is there a built-in method within npm to address this issue, or would creating a custom script that parses the package.json and executes individual npm install commands be necessary?

The concern is that without a systematic approach, potential conflicts with future dependencies might go unnoticed.

Answer №1

When it comes to legacy peer dependencies, they don't just apply on a per-package basis but affect the entire project. This means that even if you only need it for one or two dependencies, you may have to use it across your whole project. If you install a package using the --legacy-peer-deps flag and then try to install another package without it, npm will still raise issues with the initial package. Therefore, once you start using --legacy-peer-deps, you must continue to specify it for all packages you install.

The documentation suggests that you can set this attribute permanently with:

npm config set legacy-peer-deps=true --location=project

This command essentially appends legacy-peer-deps=true to the end of the .npmrc file in your project directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with the deprecated router package in Angular 2 rc3

Welcome Angular 2 rc.3! After following the instructions in the 5 Min Quickstart and using project.json to configure my project, I encountered an error when running npm install: No compatible version found: @angular/<a href="/cdn-cgi/l/email-protectio ...

Issue with babel configuration not functioning properly within the project when installed as an npm package

I recently built an npm package and included a babel.config.json file with the following content: { "presets": [ "@babel/preset-env", "@babel/preset-react" ], "plugins": [ "@babel/plugin-syntax ...

The npm package intellisense in Visual Studio 2017 is unable to locate a package from a private npm registry

tl;dr; How can I change the registry that Visual Studio 2017 intellisense searches when adding packages to package.json to a private one instead of the public? We are currently experimenting with npm package management within TFS2017 Update 1. We have con ...

vsts-npm-auth returns an error with code 1, indicating that the provided input is not a valid Base-64 string

I have set up my project to utilize a private Azure DevOps feed using the .npmrc file. Within my .js script, the following actions are carried out: const { exec } = require('child_process'); const npmrc_location = ... ...

The act of using Yarn consistently results in wiping out my node_modules folder

After successfully transitioning to using yarn instead of npm for my react-native projects on one system, I decided to copy the project to another computer. However, when trying to use yarn on the new system with yarn version 2.4.1, it ended up deleting fi ...

What is a fast way to determine if it's necessary to run npm install for

In the following script, it will iterate through all folders and install dependencies var fs = require( "fs" ), path = require( "path" ), child_process = require( "child_process" ); var rootPath = "./"; var dirs = fs.readdirS ...

What is the best way to activate a function within an npm package in a Vue application?

I'm just starting out with Vuejs and I've recently installed the vue-countup-v2 npm package. I successfully imported it into my Vue component and noticed that it works perfectly when the page loads. However, I am interested in triggering the Coun ...

The Artifactory remote npm repository is only caching the package.json files and not the TGZ files

After configuring my default registry to use a remote Artifactory repository with the command npm config set registry {registry-url}, I noticed that when running npm install, only package.json files with URLs to the dependency's repository are being c ...

Using React-Native for FTP Integration

Has anyone successfully managed to download/upload files and folders from FTP servers using react native? I tried using the react-native-ftp package but it doesn't seem to work. If you've faced a similar scenario, please share your insights! ...

The npm installation no longer resolves changes from a URL and sets it to false

The Issue Whenever I pull my team's code and execute npm install, the resolved property of certain items in package-lock.json is altered from a URL to false. For example: "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/deb ...

Creating a custom JavaScript library using an existing npm module (codius)

Embarking on a new journey with this, never tried it before. Currently utilizing https://github.com/codius/codius-host. The development of Codiu§ has been abandoned, however I am determined to salvage some parts of it for my own project. It is crucial fo ...

Sorry, I couldn't find a unique way to rewrite this text

My CentOS 7 system already has npm installed, but when I try to run the npm command, an error message pops up saying: npm: command not found [vinit@NL577 ~]$ sudo yum install npm [sudo] password for vinit: Loaded plugins: fastestmirror, langpacks L ...

Error 401 unauthorized message encountered with @scope/packagename in npm

Encountering issues while attempting to run npm install on a package due to failure with dependencies that include scoped public packages like @babel/generator. This error typically appears as a 401 Unauthorized status. Error message: Couldn't locate ...

Struggling with running my React App as I'm encountering some errors

Check out the code on Github: https://github.com/bhatvikrant/IndecisionApp I have already run npm i and then executed yarn run dev-server, utilizing webpack. My operating system is MacOs. I have also created the .babelrc file. The issue I encountered aft ...

What sets npm node-sass apart from npm sass?

Recently, I discovered that the recommended approach is to utilize @use rather than @import in sass. However, it appears that using npm sass instead of npm node-sass is necessary for this. Can you clarify the distinction between these two? Also, why do @ ...

Can someone explain the npm install messages from react-compare-app?

Scenario: I recently explored the react-compare-app example from React's examples page and decided to clone the repository. Following the usual procedure, I ran `npm install`. Initially, everything appeared normal as with most installations I have don ...

Troubleshooting Error 405 in AJAX, Javascript, Node.js (including Body-Parser and CORS), and XMLHttpRequest

I have been working on creating a JSON file from buttons. While I am able to retrieve data from the JSON files that I created, I am facing issues with posting to them using XMLHttpRequest and Ajax. Interestingly, I can add to a JSON file using routes just ...

What is the best way to remove a global npm package?

I initially set up webpack by using the following command: npm install -g webpack Now, I need to remove it: npm uninstall -g webpack However, when I check for the version, it still shows: webpack -v 3.1.0 Why is this happening? I also tried searchin ...

Whenever I try to set up a new react-app, I encounter issues with the dependency tree causing

Recently, I've been encountering an error every time I attempt to create a new react app. I've tried removing all node/npm versions and reinstalling a fresh one with the latest Node LTS, but unfortunately, the following error persists: npm ERR! ...

Heroku Application Experiencing Crashes Due to Absence of 'request-promise' Module

I am still a novice when it comes to MERN stack development (and programming in general). Currently, I am working on an app for a project using Heroku, and it seems like my proxy is encountering dependency issues. Below is the log from Heroku: 2020-04-20 ...