Reactnpmstart不起作用:“没有可用的chokidar版本”
我从 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 版本”。
其他反应项目工作正常。
回答
我遇到过同样的问题。对我有用的是强制更新本地 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.x到npm@7.x. 我通过简单地安装chokidar为DevDependency. 一切都按预期工作(开发、生产构建和测试)
如需更多保证运行:
npm i -g npm
npm cache verify
npm i -D chokidar
npm i
- It seems to be enough to just update chokidar with npm update chokidar. One command needed at least for me =)
回答
刚刚通过运行解决了我的问题
npm update chokidar
这将使用最新的 chokidar 信息更新 package-lock.json。现在在 npm 7.15 和 node 14.16 上运行 react 没有任何问题
当我从 NPM 6 更新到版本 7 时出现了原始问题。 github 中还有一个错误票:https : //github.com/facebook/create-react-app/issues/10811