【问题标题】:npm start not working in react project [duplicate]npm start 在反应项目中不起作用[重复]
【发布时间】:2018-12-25 21:57:22
【问题描述】:

我目前正在做一个 React 项目,并且已经开发了基本组件。昨天一切正常。然后我开始了一个新的 react native 项目。使用 create-react-native-app 安装项目后,npm start 命令无法启动服务器,但它对 react 项目运行良好。

我使用的是节点 10.6 和 npm 5.6。在阅读了一些建议后,我将 node 更改为 v8.11,将 npm 更改为 6.2。安装 watchman 并更换 inotify 手表后,我终于启动了原生应用程序。

今天尝试启动react项目,服务器没有启动。 这就是终端显示的内容...

  Starting the development server...

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: watch /home/maneesh/source_code/react/ytc/public ENOSPC
    at _errnoException (util.js:992:11)
    at FSWatcher.start (fs.js:1382:19)
    at Object.fs.watch (fs.js:1408:11)
    at createFsWatchInstance (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:37:15)
    at setFsWatchListener (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:80:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:228:14)
    at FSWatcher.NodeFsHandler._handleDir (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:407:19)
    at FSWatcher.<anonymous> (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:455:19)
    at FSWatcher.<anonymous> (/home/maneesh/source_code/react/ytc/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:460:16)
    at FSReqWrap.oncomplete (fs.js:153:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ytc@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ytc@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我使用的是 ubuntu 18.04 节点 8.11 npm 6.2

知道可能是什么问题吗?

【问题讨论】:

  • 嗨,可能是 this 的副本,或者查看 this
  • 是的!第二个链接有效。谢谢

标签: node.js reactjs npm


【解决方案1】:

您可以运行以下命令来避免 ENOSPC:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

对于 Arch Linux,将此行添加到 /etc/sysctl.d/99-sysctl.conf:

fs.inotify.max_user_watches=524288

最后,运行:

sysctl --system

这也将在重新启动后持续存在。

来源:https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

【讨论】:

    【解决方案2】:

    试试这个

    create-react-app my-app
    cd my-app
    npm install react-scripts@2.1.8
    npm start
    

    【讨论】:

    • 你能解释一下为什么这解决了原来的问题吗?您在这里所做的只是创建一个新项目并启动它。
    • 它对我有用,我安装了 node js,之后我使用 node js 命令提示符和 npm install -g create-react-app,然后 create-react-app my-app,然后 npm start ,毕竟我得到了这个错误,然后我使用了 cd my-app,然后 npm install react-scripts@2.1.8 和最后 npm start,它对我有用
    猜你喜欢
    • 1970-01-01
    • 2020-03-20
    • 2018-10-26
    • 2021-08-17
    • 2021-03-11
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多