javascriptnpmjson-server

Unexpected errors and warnings when running json-server --watch


I'm trying to use json-server as follows:

$ json-server --watch db.json

However, I'm getting errors or warnings when I run that command, depending on the version I have installed:

Minimal package file (update version of json-server as needed):

{
  "name": "q77787616",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "json-server --watch db.json"
  },
  "keywords": [],
  "license": "ISC",
  "dependencies": {
    "json-server": "1.0.0-alpha.12"
  }
}

Solution

  • json-server is currently in active development towards v1, but unfortunately these alpha versions are being published to npm with the latest tag, so are being installed in favour of the stable version (currently 0.17.4) if you simply npm install json-server. This has caused various issues:

    You can check which version you currently have installed with:

    npm ls json-server
    

    Given the active development and alpha status, the best thing to do currently is to explicitly install the stable version (the documentation for this is still available here):

    $ npm install json-server@0
    

    Alternatively, if you want to use the alpha v1 and are using an appropriate Node.js version (i.e. ^16.17 || >=18.3), you can npm install json-server@latest to get the latest version (ensure you have at least alpha.14) and use the command without the --watch flag:

    $ json-server db.json