无法在React Native中启动npm

时间:2018-09-04 12:20:23

标签: react-native npm

我正在尝试使用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

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

听起来像您已经在运行打包程序,或者只是在端口8081上运行了其他程序,因此打包程序尝试启动但无法启动,因为某些内容已经在该端口上监听。

如果您在开发机器上,并且没有其他有意义的node.js进程在运行,那么您可以执行以下命令对其进行整理。

killall node && npm start 

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

注意:应该可以在MacOS和Linux上使用。

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

    lsof -i:8081 
    
  2. (猛烈地)杀死它,假设端口8081上正在运行某些东西

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

    npm start
    

答案 1 :(得分:0)

当您运行具有相同端口的另一个进程(8081)时,会发生此问题 首先查看进程ID,它们在同一端口上运行。 尝试

lsof -i :8081

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

您可以杀死那些人,

kill -9 454 21922

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

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