create-react-app: Error: No version of chokidar is available. Tried chokidar@2 and chokidar@3. after upgrading npm to 7.*.*

Describe the bug

using ejected CRA , it compiles successfully and then it breaks showing below error… it started happend when i updated npm to 7 from 6

Did you try recovering your dependencies?

i tried runnung npm npm cache verify && rm -rf node_modules/ && npm i but it did not worked

Environment

node: v14.16.0 npm: 7.9.0

OS: Linux (Ubuntu) ├── webpack-dev-server@3.11.0 ├── webpack-manifest-plugin@2.2.0 ├── webpack@4.44.2

Steps to reproduce

npm start

Expected behavior

should run the server succsessfully

Actual behavior

You can now view webrms in the browser.

  Local:            http://localhost:3001
  On Your Network:  http://192.168.0.160:3001

Note that the development build is not optimized.
To create a production build, use npm run build.

/home/murtaza/umai/webrms/node_modules/watchpack/lib/chokidar.js:17
throw new Error(
^

Error: No version of chokidar is available. Tried chokidar@2 and chokidar@3.
You could try to manually install any chokidar version.
chokidar@3: Error: Cannot find module 'chokidar'
Require stack:
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/chokidar.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/DirectoryWatcher.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/watcherManager.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/watchpack.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/node/NodeWatchFileSystem.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/webpack.js
- /home/murtaza/umai/webrms/scripts/start.js
chokidar@2: Error: Cannot find module 'watchpack-chokidar2'
Require stack:
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/chokidar.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/DirectoryWatcher.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/watcherManager.js
- /home/murtaza/umai/webrms/node_modules/watchpack/lib/watchpack.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/node/NodeWatchFileSystem.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js
- /home/murtaza/umai/webrms/node_modules/webpack/lib/webpack.js
- /home/murtaza/umai/webrms/scripts/start.js

    at Object.<anonymous> (/home/murtaza/umai/webrms/node_modules/watchpack/lib/chokidar.js:17:7)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/murtaza/umai/webrms/node_modules/watchpack/lib/DirectoryWatcher.js:9:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    ```

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 21
  • Comments: 26

Commits related to this issue

Most upvoted comments

I can confirm that downgrading to npm@7.5.4 works.

It also started working with npm@7.13.0 after running npm update --force command. Looks like the reason is that after the command watchpack starts using v3 of chokidar:

Before update

$ npm ls chokidar
└─┬ react-scripts@4.0.3
  └─┬ webpack-dev-server@3.11.1
    └── chokidar@2.1.8

After update

$ npm ls chokidar
└─┬ 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 update --legacy-peer-deps Worked for me, Chokidar 2 has problems with node 14v+. Upgrade to Chokidar 3 is necessary.

its something definitely wrong with npm 7.*.* … i tried npm i --legacy-peer-deps and it worked for me…

however it shouldn’t be like this and dependencies should handled in latest stable version… also haven’t tried removing node_modules and running npm i after it…

here is the detailed reasoning of why it may cause: https://stackoverflow.com/questions/66239691/what-does-npm-install-legacy-peer-deps-do-exactly-when-is-it-recommended-wh/66620869#66620869

I had to create a brand new “create-react-app”. Then copy all my sources in the new folder (and use yarn instead of npm) lol

Did some more testing, 7.5.4 works, 7.5.5+ fails.

OK, so this actually seems to be a Node issue, I was running 15.14 and running into this issue.

I’ve installed nvm and set it to use Node 12.22.1 (latest v12 at time of writing) and npm run start now works correctly.

This makes sense because the npm i message indicated that chokidar would not work on Node 14+.

It looks like the chokidar requirements comes from react-scripts->webpack-dev-server and unfortunately, they don’t upgrade to chokidar v3 until webpack-dev-server v4, which is still in beta. So, I guess we’re stuck with running CRA on Node 12 for now.

I fixed it by using node v12.22.3 AND installing chokidar as a Dev Dependency You can use nvm for that (https://github.com/nvm-sh/nvm)

nvm install 12.22.3
nvm use 12.22.3
npx create-react-app my-app
cd my-app
npm i -D chokidar
npm start

Yay, npm is working again! Love the turnaround time on this guys!

node: v14.17.1 <- nice

Yep, npm 7.17.0 failed, yarn 1.22.10 worked. I actually prefer npm, sad day, but I have to roll with what works and spend my time debugging my own mess.

os: Pop!_OS 20.04 LTS (ubuntu 20.04 LTS) node: v14.17.0 npm: 7.17.0 yarn: 1.22.10

“react”: “^17.0.2”, “react-dom”: “^17.0.2”, “react-scripts”: “4.0.3”,

Attempted to install chockidar with npm. $ npm i chokidar npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for fsevents@2.3.2: wanted {“os”:“darwin”} (current: {“os”:“linux”,“arch”:“x64”}) npm ERR! notsup Valid OS: darwin npm ERR! notsup Valid Arch: undefined npm ERR! notsup Actual OS: linux npm ERR! notsup Actual Arch: x64

Hope this helps, someone get around it and the npm or chockidar guys can fix it for the next release.

I had to create a brand new “create-react-app”. Then copy all my sources in the new folder (and use yarn instead of npm) lol

lol! @alex-drocks I was about to do the same then I thought I might encounter a more nagging error.

Chockidar is a dependency inside webpack that takes care of hot reloads on save on development environment.

Chockidar 2 has problems with node v14+.

For me, npm update did update webpack to use chockidar 3 hence it finally started working.

Faced this issue when I updated from npm 6 to npm 7. I have not ejected. First I just installed chokidar as a dev dependency and then it works again with Node 14.16.0 npm 7.15.0

Edit: I just tried removing the dev dependency and then using “npm update chokidar” which updated my package-lock.json it now also works without having it as a dev dependency in the package.json

Why I have to do this: no idea.