简体   繁体   中英

Getting an error when I run NPM live-server

Here's the server I'm using, https://www.npmjs.com/package/live-server . However, when I try to use ~/.live-server.json as the configuration file, I always fail... Here's what I have in the file, and it's very simple.

{
   port: "8001"
}

Then I have this error when I run live-server

undefined:2
   port: "8001"
   ^    

SyntaxError: Unexpected token p
    at Object.parse (native)
    at Object.<anonymous> (/usr/local/lib/node_modules/live-server/live-server.js:17:20)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

I don't know why this is happening.

Property names in JSON must be quoted (JSON is not JavaScript):

{
   "port": "8001"
}

It should be:

{
    "port": 8001
}

Add explanation: well, in JSON, name should always double quoted, and value should also be double quoted, except number (if you double quote a number, it becomes a string). Like this:

{
    "name1": "stringValue",
    "name2": aNumber
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM