Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Again "json-server module not found" #1500

Open
Drachenfels opened this issue Jan 24, 2024 · 11 comments
Open

Again "json-server module not found" #1500

Drachenfels opened this issue Jan 24, 2024 · 11 comments

Comments

@Drachenfels
Copy link

Drachenfels commented Jan 24, 2024

I am trying to follow one older tutorial: https://www.journeytoawebapp.com/posts/local-mock-server-with-node

Fresh repository I copy-pasted the code:

const jsonServer = require('json-server');
const server = jsonServer.create();
const middlewares = jsonServer.defaults();
const accounts = require('./responses/accounts/accounts');

const PORT = process.env.PORT || 3001;

server.use(middlewares);

server.get('/accounts', (req, res) => {
    res.jsonp(accounts);
})

server.listen(PORT, () => {
    console.log('Server running at http://127.0.0.1:' + PORT);
})

I did npm install json-server and I have this:

{
  "dependencies": {
    "json-server": "^1.0.0-alpha.22"
  }
}

But when I try to run the code with node server.js:

node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'json-server'
Require stack:
- <blip>/exp/server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (<blip>/exp/server.js:1:20)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<blip>/exp/server.js' ]
}

My root:

$ ls -l
total 36
drwxrwxr-x 40 drachenfels drachenfels  4096 Jan 24 16:38 node_modules
-rw-rw-r--  1 drachenfels drachenfels    65 Jan 24 16:38 package.json
-rw-rw-r--  1 drachenfels drachenfels 22382 Jan 24 16:38 package-lock.json
-rw-rw-r--  1 drachenfels drachenfels   411 Jan 24 16:38 server.js

My node_modules:

$ ls -l node_modules/
total 148
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 anymatch
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 binary-extensions
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 braces
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 chalk
drwxrwxr-x  4 drachenfels drachenfels 4096 Jan 24 16:38 chokidar
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 dot-prop
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 es-escape-html
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 es-vary
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 eta
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 fill-range
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 glob-parent
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 header-range-parser
drwxrwxr-x  5 drachenfels drachenfels 4096 Jan 24 16:38 inflection
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 ipaddr.js
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 is-binary-path
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 is-extglob
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 is-glob
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 is-number
drwxrwxr-x  4 drachenfels drachenfels 4096 Jan 24 16:38 json5
drwxrwxr-x  5 drachenfels drachenfels 4096 Jan 24 16:38 json-server
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 lowdb
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 milliparsec
drwxrwxr-x  4 drachenfels drachenfels 4096 Jan 24 16:38 mime
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 mrmime
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 negotiator
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 normalize-path
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 picomatch
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 @polka
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 readdirp
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 regexparam
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 sirv
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 sort-on
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 steno
drwxrwxr-x 20 drachenfels drachenfels 4096 Jan 24 16:38 @tinyhttp
drwxrwxr-x  2 drachenfels drachenfels 4096 Jan 24 16:38 to-regex-range
drwxrwxr-x  4 drachenfels drachenfels 4096 Jan 24 16:38 totalist
drwxrwxr-x  3 drachenfels drachenfels 4096 Jan 24 16:38 type-fest

My NODE_PATH is empty (in case it's relevant):

echo $NODE_PATH

@patrickpie83
Copy link

patrickpie83 commented Jan 25, 2024

I have a similar error.
Today I was trying to use json-server-auth, but end up with the error message.

Let me put the error first:

node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'json-server'
Require stack:
- /usr/local/lib/node_modules/json-server-auth/dist/guards.js
- /usr/local/lib/node_modules/json-server-auth/dist/bin.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/json-server-auth/dist/guards.js:6:20)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/local/lib/node_modules/json-server-auth/dist/guards.js',
    '/usr/local/lib/node_modules/json-server-auth/dist/bin.js'
  ]
}

Node.js v20.11.0

In my project, I use npm init to create package.json

then use npm install -D json-server json-server-auth to create node_modules, package-lock.json

and then create db.json file in my project

and use sudo npm install -g json-server-auth ,

then I finally use json-server-auth db.json, but it doesn't start the server,
showed the Error: Cannot find module 'json-server'

package.json code

{
  "name": "vue-hangout-server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "json-server": "^1.0.0-alpha.22"
  },
  "dependencies": {
    "express": "^4.18.2",
    "json-server-auth": "^2.1.0"
  }
}

I'm sure I install the latest version json-server and json-server-auth,

How can I make sure it finds module 'json-server'?

@syukronarie
Copy link

Looks like there is an issue in alpha version.

I can able to run normally using json-server@^0.17.3

@filipopo
Copy link

filipopo commented Feb 8, 2024

Can confirm, it works on 0.17.4 but not on the latest release

@ritheesh4
Copy link

This issue exists for me also.

@sjaelselement
Copy link

Да, проблема в версии. npm i json-server@0.17.4 - решение

@PaperPesto
Copy link

Confirm, doesn't work with version 1.0.0-alpha.23

@ritheesh4
Copy link

Correct. This issue is existing with the latest version. It does not there in "0.16.3".

@lbombassei
Copy link

Any ETA on fixing? It's great to have paging and sorting already done by json-server

@Drachenfels
Copy link
Author

Any ETA on fixing? It's great to have paging and sorting already done by json-server

Tool feels to be if not abandoned then not under active development. So probably would need forking or something.

@Denver-Ning
Copy link

doesn't work with version "^1.0.0-alpha.23", I use "0.17.4" version is OK

@MedvidekPu
Copy link

Looks like there is an issue in alpha version.

I can able to run normally using json-server@^0.17.3

just spent 3 hours debugging this just to find out it was the version issue. Thank you so much for the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants