'npm install gets the error "must provide string spec"

I try to execute an old react app which is created by myself two years ago. When I try to run the app via "npm install", I've got the following error:

npm ERR! must provide string spec
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\tws80\AppData\Local\npm-cache\_logs\2022-01-09T21_00_13_180Z-debug.log

The dependencies of my package.json file:

  "dependencies": {
    "@material-ui/core": "^4.9.7",
    "@material-ui/icons": "^4.9.1",
    "@mdi/js": "^5.0.45",
    "@mdi/react": "^1.3.0",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.1",
    "@testing-library/user-event": "^7.2.1",
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "husky": "^4.2.3",
    "i18next": "^19.3.3",
    "lint-staged": "^10.0.8",
    "prettier": "^1.19.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2", 
    "react-html-email": "^3.0.0",
    "react-i18next": "^11.3.3",
    "react-intl": "^4.1.1",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^5.0.0"
  }

My current node and npm version:

node -v v16.13.1
npm -v 8.1.2

I suppose this error is due to the old dependencies but I don't find any useful workaround to solve this problem. After I've removed node_modules I still can re-install node_modules. Thank you for your help.



Solution 1:[1]

Running "rm -rf node_modules && rm -rf package-lock.json && npm i" in a bash terminal fixed it for me.

Running npm -v --> 8.3.0 on my local machine

Solution 2:[2]

The problem is that you put some package options into the "dependencies" part of your package.json. I had the same bug with autoprefixer browserlist options. Remove "editor.formatOnPaste": true and "editor.formatOnSave": true and the npm install will work as expected - I did check it locally. My guess is that under "dependencies" or "devDependencies" only packages' versions are expected.

Solution 3:[3]

After I create a new react app and then copy & paste the package.json from the new app into the old app, the command npm install does work. Thanks a lot!

Solution 4:[4]

Your npm package has to be initialized first:
npm init
Afterwards you should bee able to execute your commands.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erik Grosskurth
Solution 2 Rych
Solution 3 Kai-Chun Lin
Solution 4 David