vue run dev 报错npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] dev: webpack-dev-server -

新接手一个项目vue run dev报错,如下:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

研究半天发现是端口问题

修改方法:

打开config文件夹下的index.js文件找到如下图这段代码:

 // Various Dev Server settings
    host:'192.168.1.1', // can be overwritten by process.env.HOST
    port: 8102, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

host 修改为获取本机ip

封装好的的代码:

/*
  获取本机ip
*/
function getIPAddress(){
  var interfaces = require('os').networkInterfaces();
  for(var devName in interfaces) {
      var iface = interfaces[devName];
      for(var i = 0; i

引入 :

 // Various Dev Server settings
    host:getIPAddress(), // can be overwritten by process.env.HOST
    port: 8102, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

保存然后 vue run dev  就可以啦! 还有问题可以咨询留言

你可能感兴趣的:(vue)