npm install 收到错误“必须提供字符串规范”

Kai*_*Lin 24 node.js reactjs

我尝试执行两年前我自己创建的一个旧的 React 应用程序。当我尝试通过“npm install”运行应用程序时,出现以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我的 package.json 文件的依赖项:

  "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"
  }
Run Code Online (Sandbox Code Playgroud)

我当前的节点和 npm 版本:

node -v v16.13.1
npm -v 8.1.2
Run Code Online (Sandbox Code Playgroud)

我认为此错误是由于旧的依赖项造成的,但我没有找到任何有用的解决方法来解决此问题。删除node_modules后,我仍然可以重新安装node_modules。感谢您的帮助。

Eri*_*rth 31

rm -rf node_modules && rm -f package-lock.json && npm ibash终端中运行为我解决了这个问题。

在我的本地机器上运行npm -v产量 -->8.3.0


小智 11

不需要创建新的包。删除package-lock.json并运行npm install我解决了我的问题。


小智 5

问题是您将一些包选项放入 package.json 的“依赖项”部分。我对自动前缀浏览器列表选项也有同样的错误。删除"editor.formatOnPaste": true"editor.formatOnSave": true安装 npm 将按预期工作 - 我确实在本地检查了它。我的猜测是,在“依赖项”或“devDependency”下,仅需要包的版本。


Kai*_*Lin 0

在我创建了一个新的反应应用程序,然后将package.json新应用程序复制并粘贴到旧应用程序中后,该命令npm install确实起作用了。