首页 > 解决方案 > 无法在 react native 中启动 npm

问题描述

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

并收到此错误:

> 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

谁能帮我?

标签: react-nativenpm

解决方案


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

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

killall node && npm start 

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

注意:应该适用于 MacOS 和 Linux。

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

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

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

    npm start
    

推荐阅读