33

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

在此处输入图像描述

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

在此处输入图像描述

也试过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 版本”相同的错误。

其他反应项目运行良好。

4

8 回答 8

33

我遇到过同样的问题。对我有用的是强制更新本地 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 无需任何更改即可工作。

于 2021-03-29T08:51:54.630 回答
22

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

npm update chokidar

这将使用最新的 chokidar 信息更新 package-lock.json。现在运行 react,npm 7.15 和节点 14.16 没有任何问题。无需强制安装或做任何古怪的事情。只需更新 chokidar 以使您的包文件保持一致并为团队中的每个人保持开发运行。

当我从 NPM 6 更新到版本 7 时出现了原始问题。github 中还有一个 bug 票:https ://github.com/facebook/create-react-app/issues/10811

于 2021-05-28T12:54:11.213 回答
15

The same problem occurred to me after upgrading from npm@6.x to npm@7.x. I solved my problem with simply installing chokidar as a DevDependency. Everything works as expected (development, production build and tests)

For more assurance run:

npm i -g npm
npm cache verify
npm i -D chokidar
npm i
于 2021-04-03T08:48:38.970 回答
5

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

Chuckidar 2 在节点 v14+ 上存在问题。

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

于 2021-04-02T07:52:29.443 回答
3

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

方法一:

npm i chokidar@latest --force

这对我有用。npm 本身说:npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. 升级到 chokidar 3,依赖项减少 15 倍。


方法二(推荐):

npm 审计修复

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

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


方法三:

  • 将 npm 版本降级到 6

方法四:

npm 更新 --force

不建议用于大型项目。

于 2021-07-29T18:17:04.167 回答
3

您需要更新 chokidar。所以只需要点击命令 npm update chokidarnpm 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

就是这样,它是如何为我工作的。

于 2021-07-13T07:59:20.280 回答
2

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

npm update chokidar

于 2021-07-02T08:37:56.300 回答
0

我今天遇到了这个问题,我到处搜索,然后用这个解决我的问题:

$ npm 更新 --force

于 2021-12-10T08:18:22.387 回答