edinvnode
edinvnode

Reputation: 3547

node.js Cannot find module './lib/compat'

I am running a JavaScript code on Ubuntu server using node.js I got this error.

module.js:340
    throw err;
          ^
Error: Cannot find module './lib/compat'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/lib/nodejs/node_modules/express/node_modules/depd/index.js:11:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

How to debug this error?

Edit: using these dependencies.

var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');

Upvotes: 7

Views: 12822

Answers (2)

Deadly
Deadly

Reputation: 131

The problem can persist even after running:

npm uninstall express
npm install express --save

If this happens delete the node-modules folder and then run:

npm install express

and

npm install

to reinstall all the packages listed in packages.json

Upvotes: 11

Mehdi
Mehdi

Reputation: 7403

The problem is not directly in your code, but in the dependency of one of the modules you're using. You see it at this line of the error message:

    at Object.<anonymous> (/usr/lib/nodejs/node_modules/express/node_modules/depd/index.js:11:24)

express module has a dependency called depd, which is the module in trouble.

How did you install your modules?

There has probably been some problem when you have installed express.

The folder lib/compat is directly part of depd, so there's no reason it should be missing.

You may want to do the following:

npm uninstall express
npm install express --save

This would reinstall express, hopefully solving the issue.

Upvotes: 7

Related Questions