简体   繁体   中英

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');

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.

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

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