【问题标题】:Cannot start npm in the react native无法在 react native 中启动 npm
【发布时间】:2019-09-26 19:15:57
【问题描述】:

我正在尝试使用 React Native 我尝试运行应用程序 npm 开始

并收到此错误:

> ERROR  Metro Bundler can't listen on port 8081 Loading dependency
> graph...npm ERR! code ELIFECYCLE npm ERR! errno 11 npm ERR!
> MyFirstDemo@0.0.1 start: `node
> node_modules/react-native/local-cli/cli.js start` npm ERR! Exit status
> 11 npm ERR!  npm ERR! Failed at the MyFirstDemo@0.0.1 start script.
> npm ERR! This is probably not a problem with npm. There is likely
> additional logging output above. npm ERR! A complete log of this run
> can be found in: npm ERR!    
> /home/nidhi/.npm/_logs/2018-09-04T12_11_05_454Z-debug.log

谁能帮帮我?

【问题讨论】:

  • 您使用的是什么操作系统? Linux?
  • 请编辑您的错误帖子,最后告诉我们您是使用原生反应还是世博会
  • @SGhaleb, Linux
  • 您可以在终端中尝试 ...lsof -i :8081 以查看正在使用该端口的内容,然后按照此正确/安全地终止进程...。unix.stackexchange.com/questions/8916/…
  • @SGhaleb 它现在正在工作。谢谢大家的回复。

标签: react-native npm


【解决方案1】:

听起来您已经有一个打包程序在运行,或者只是在端口 8081 上运行了其他东西,因此打包程序尝试启动但不能,因为该端口上已经有东西在监听。

如果你在你的开发机器上,并且没有其他有意义的 node.js 进程在运行,那么你可以执行以下来解决它。

killall node && npm start 

如果您不想杀死机器上的每个节点进程,嘿,有些可能很重要...您只想杀死在该端口上运行的进程。

注意:应该可以在 MacOS 和 Linux 上运行。

  1. 查看该端口上是否有进程(可选步骤)

    lsof -i:8081 
    
  2. 杀死它(暴力地),假设端口 8081 上有东西在运行

    kill -9 $(lsof -t -i:8081)
    
  3. 现在尝试再次运行打包程序。

    npm start
    

【讨论】:

    【解决方案2】:

    当您使用相同端口 (8081) 运行另一个进程时会出现此问题 首先查看在同一端口上运行的进程 ID。 试试看,

    lsof -i :8081
    

    输出结果如下。 process that are running using the same port

    你可以杀死那些,

    kill -9 454 21922
    

    再次尝试 npm start。 如果这些命令不起作用,请尝试使用 sudo 运行它们。

    sudo lsof -i :8081
    sudo kill -9 454 21922
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-17
      • 2019-11-20
      • 2016-05-28
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      相关资源
      最近更新 更多