微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React npm start 不起作用:“没有可用的 chokidar 版本” 之前之后更新

如何解决React npm start 不起作用:“没有可用的 chokidar 版本” 之前之后更新

我从 Github 克隆了我已经在 Github Pages 上运行的 React-Typescript 应用程序,并希望进行一些更改。我运行 npm install 并安装了所有依赖项,但是当我运行 npm start 时,出现此错误

enter image description here

我不知道 chokidar 是什么,我看了一点,我认为它与我的项目无关。我仍然尝试 npm install chokidar 并且我遇到了另一个这样的错误

enter image description here

也尝试过 npm audit fix。修复了一些东西,但没有任何改变。

所以我无法打开开发服务器。另外,这是 package.json 文件

// package.json
{
  "name": "panflix","homepage": "https://absolutezero13.github.io/meerkast/","version": "0.1.0","private": true,"dependencies": {
    "@testing-library/jest-dom": "^5.11.4","@testing-library/react": "^11.1.0","@testing-library/user-event": "^12.1.10","@types/enzyme": "^3.10.8","@types/jest": "^26.0.15","@types/node": "^12.0.0","@types/react": "^17.0.0","@types/react-dom": "^17.0.0","@types/redux-devtools": "^3.0.47","axios": "^0.21.1","enzyme": "^3.11.0","firebase": "^8.2.7","gh-pages": "^3.1.0","history": "^4.10.1","react": "^17.0.1","react-bootstrap": "^1.5.0","react-dom": "^17.0.1","react-redux": "^7.2.2","react-router-dom": "^5.2.0","react-scripts": "4.0.2","redux": "^4.0.5","redux-devtools-extension": "^2.13.8","redux-thunk": "^2.3.0","typescript": "^4.1.2","web-vitals": "^1.0.1"
  },"scripts": {
    "predeploy": "npm run build","deploy": "gh-pages -d build","start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
  },"eslintConfig": {
    "extends": [
      "react-app","react-app/jest"
    ]
  },"browserslist": {
    "production": [
      ">0.2%","not dead","not op_mini all"
    ],"development": [
      "last 1 chrome version","last 1 firefox version","last 1 safari version"
    ]
  },"devDependencies": {
    "@types/react-redux": "^7.1.16","@types/react-router-dom": "^5.1.7"
  }
}


我试过 npm install -g chokidar 并安装了它。但是我收到了与之前相同的错误“没有可用的 chokidar 版本。”

其他 React 项目运行良好。

解决方法

我遇到了同样的问题。对我有用的是强制更新本地 npm 包:

npm update --force

之前

$ npm list chokidar
pwa-react-showcase@0.1.0
└─┬ react-scripts@4.0.3
  └─┬ webpack-dev-server@3.11.1
    └── chokidar@2.1.8

之后

$ npm list chokidar
pwa-react-showcase@0.1.0
└─┬ react-scripts@4.0.3
  ├─┬ webpack-dev-server@3.11.1
  │ └── chokidar@2.1.8
  └─┬ webpack@4.44.2
    └─┬ watchpack@1.7.5
      ├── chokidar@3.5.1
      └─┬ watchpack-chokidar2@2.0.1
        └── chokidar@2.1.8

更新

我们发现 NPM 7 是问题所在。降级到 NPM 6.14.12 无需任何更改。

,

npm@6 升级到 npm@7 后,我遇到了同样的问题。我通过简单地将 chokidar 安装为 DevDependency 解决了我的问题。一切都按预期进行(开发、生产构建和测试)

更多保证运行:

npm i -g npm
npm cache verify
npm i -D chokidar
npm i
,

刚刚通过运行解决了我的问题

npm 更新 chokidar

这将使用最新的 chokidar 信息更新 package-lock.json。现在在 npm 7.15 和 node 14.16 上运行 react 没有任何问题

原来是我从NPM 6升级到7的时候出现的问题。github上也有bug:https://github.com/facebook/create-react-app/issues/10811

,

Chockidar 是 watchpak 中的一个依赖项,它负责在保存开发环境时进行热重载。

Chuckidar 2 在 node v14+ 上有问题。

对我来说,npm update 确实更新了 watchpack 以使用 chockidar 3。

,

您需要更新 chokidar。所以只需要点击命令 npm update chokidar 要么 npm update chokidar@2

如果你得到像这样的错误 invalid json response body at https://registry.npmjs.org/chokidar reason: Unexpected end of JSON input

那么主要原因可能是缓存,所以你必须清理缓存。为此,点击命令 npm cache clean --force

在此之后,如果您再次遇到像这样的错误

 `ENOENT: no such file or directory,scandir '/node_modules/node-sass/vendor'`

然后你需要重建节点sass,通过点击命令 npm rebuild node-sass

就是这样,它对我有用。

,

更新 Chokidar 依赖项为我解决了这个问题。

npm update chokidar

,

是因为chokidar的版本需要更新到3

方法一:

npm i chokidar@latest --force

这对我有用。 npm 本身说:npm WARN deprecated chokidar@2.1.8:Chokidar 2 将在节点 v14+ 上崩溃。升级到 chokidar 3,依赖项减少 15 倍。


方法二(推荐):

npm 审计修复

如果您通过公司网络上的代理进行连接,这可能对您不起作用,您可能会得到这样的结果:

npm 错误!审核端点返回错误


方法三:

  • 将 npm 版本降级到 6

方法四:

npm update --force

不推荐用于大型项目。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。