0

enter image description here

Please anyone help me on my laptop when i live-server public enter after install -g live-server then show this text and not open in browser:-

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

Error: spawn cmd ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn cmd',
  path: 'cmd',
  spawnargs: [ '/c', 'start', '""', '/b', 'http://127.0.0.1:8080' ]
Parth Shah
  • 1,237
  • 10
  • 24

2 Answers2

0

Just run the Command Prompt as Administrator before running live-server and things should work the way they should.

Edit: Actually no. I had the same problem and tried that: it worked but (later discovered) for some reason works only if we run 'live-server' from C:\Windows\System32>. We're back to square one. Sorry.

0

I had a similar issue now, not exactly the same, but I think my suggested solution will work.

But first, your issue seems you don't have the global node_modules folder in your path. You can check this with echo $PATH from cmd and set it by searching for "environment variables" after pressing windows button once.

Even if most packages suggest installing them with -g this is actually usually not the best, mainly because your project will not be self-contained. So you will always need to globally install your dependencies when on a new machine, production server, etc...

While it's convenient to not have to download some packages often used on the development machine, it's much safer to run npm/yarn install without -g and then wait for a minute extra after your cloned the project (i bet many people disagree with me on that).

Anyway, there are a few tricks with live-reload and I found it hard to use unless run as a script. Not only because of this reason but also because it looks for .live-reload.json config inside the home folder for the user and this cant be specified as an argument.

TLDR; This is the relevant parts from my project, this should work for you as well:

package.json

{
  scripts:{
    "local": "yarn build && node live-server.js",
    "build"  : "#install other dependencies"
  },
  "devDependencies": {
    "live-server": "^1.2.1"
  }
}

live-server.js

var liveServer = require("live-server");
const path = require('path');

var params = {
    port: 8181, // Set the server port. Defaults to 8080.
    host: "127.0.0.1", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
    root: path.join(__dirname, '/public'), // Set root directory that's being served. Defaults to cwd.
    open: true, // When false, it won't load your browser by default.
    wait: 100, // Waits for all changes, before reloading. Defaults to 0 sec.
    logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
};
liveServer.start(params);
Patrik Grinsvall
  • 584
  • 1
  • 4
  • 22