javascript 如何修复“TypeError:fsevents 不是构造函数”反应错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56057325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:35:20  来源:igfitidea点击:

How to fix "TypeError: fsevents is not a constructor" react error

javascriptnode.jsreactjs

提问by Nandkumar

While staring React app using npm start this error occurred...

使用 npm start 凝视 React 应用程序时发生此错误...

I tried below things:

我尝试了以下事情:

  1. remove node_module package and reinstall

  2. use yarn instead npm

  1. 删除 node_module 包并重新安装

  2. 使用纱线代替 npm

3.update fsevent library using npm

3.使用npm更新fsevent库

still getting this error

仍然收到此错误

Note: If we create react app fresh/new yarn start will work, but we close the terminal and restart using same thing below error occurred

注意:如果我们创建 react app fresh/new yarn start 将起作用,但我们关闭终端并使用以下相同的东西重新启动发生错误

/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28

return (new fsevents(path)).on('fsevent', callback).start(); ^

return (new fsevents(path)).on('fsevent', callback).start(); ^

TypeError: fsevents is not a constructor at createFSEventsInstance (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28:11) at setFSEventsListener (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:82:16) at FSWatcher.FsEventsHandler._watchWithFsEvents (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:252:16) at FSWatcher. (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:386:25) at LOOP (fs.js:1565:14) at process._tickCallback (internal/process/next_tick.js:61:11) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/runfor documentation about this command.

TypeError: fsevents 不是 createFSEventsInstance (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28:11) at setFSEventsListener (/Users/nannam/test-app-2) 的构造函数/node_modules/chokidar/lib/fsevents-handler.js:82:16) 在 FSWatcher.FsEventsHandler._watchWithFsEvents (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:252:16 ) 在 FSWatcher。(/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:386:25) at LOOP (fs.js:1565:14) at process._tickCallback (internal/process/next_tick. js:61:11) 错误命令失败,退出代码为 1。信息 访问 https://yarnpkg.com/en/docs/cli/run获取有关此命令的文档。

回答by zyMacro

npm audit fix --force

It worked in my case

它在我的情况下有效

回答by Saurabh Mistry

below steps solved issue :

以下步骤解决了问题:

  • step 1 : removing node_moduleand yarn.lock
  • step 2 : yarn install
  • step 3 : yarn start
  • 第 1 步:删除node_moduleyarn.lock
  • 第 2 步:纱线安装
  • 第 3 步:纱线开始

enter image description here

在此处输入图片说明

回答by Moses Okemwa

This is a well-documented issue on the react GitHub repowith a couple of options to try.

这是react GitHub repo 上的一个有据可查的问题,有几个选项可供尝试。

I solved my error by re-installing the fsevents npm i fsevents, which worked

我通过重新安装 fsevents 解决了我的错误npm i fsevents,它起作用了

回答by crazy_Y

The @not-a-file gave will work only you can install the fsevents successfully。 but when I do that, I receive an error with this:

给出的@not-a-file 将起作用,只有你可以成功安装 fsevents。但是当我这样做时,我收到一个错误:

Error: EACCES: permission denied, mkdir '/Users/**/node_modules/jest-haste-map/node_modules/fsents/.node-gyp'

So ,I suggest you avoid this by use something like this:

所以,我建议你通过使用这样的东西来避免这种情况:

sudo npm i fsevents --unsafe-perm=true --allow-root

And I also find this error may due to node version, when I use node 12,I can not install fsevents successfully , so I use nvm to modify my node version to v11.15.0

而且我也发现这个错误可能是由于节点版本,当我使用节点12时,我无法成功安装fsevents,所以我使用nvm将我的节点版本修改为v11.15.0

回答by Arthur Menezes

I solved with

我解决了

sudo npm i fsevents --unsafe-perm

回答by Parthan_akon

I also had the same issue though am using MacOS the issue is kind of bug. I solved this issue by repeatedly running the commands,

我也有同样的问题,虽然我使用的是 MacOS,但问题是一种错误。我通过重复运行命令解决了这个问题,

  • sudo npm cache clean --force
  • sudo npm uninstall
  • sudo npm install
  • 须藤 npm 缓存清洁 --force
  • 须藤 npm 卸载
  • 须藤 npm 安装

One time it did not worked but when I repeatedly cleaned the cache and after uninstalling npm, reinstalled npm, the error went off. Am using Angular 8 and this issue is common

有一次它不起作用,但是当我反复清理缓存并在卸载 npm 后重新安装 npm 时,错误消失了。我正在使用 Angular 8,这个问题很常见

回答by Can Rau

Solved it using Yarn's selective dependency resolutions

使用 Yarn 的选择性依赖解析解决了它

"resolutions": {
  "chokidar": "^3.3.1"
},

as some packages in my dependencies are still on older chokidar versions < 3

因为我的依赖项中的某些包仍然在较旧的 chokidar 版本上 <3

回答by ohkts11

For me, downgrading node to v11.15.0 solved the error.

对我来说,将 node 降级到 v11.15.0 解决了错误。

回答by Lakshman Raj Vasudevan

I deleted the node modules package and reinstalled the node and then executed the node js commands. it worked fine for me.

我删除了节点模块包并重新安装了节点,然后执行了节点js命令。它对我来说很好。

回答by CrsCaballero

I solved changed my "package.json" using this react-scripts": "2.1.8

我用这个解决了改变我的“package.json” react-scripts": "2.1.8