简体   繁体   English

node.js找不到模块'./lib/compat'

[英]node.js Cannot find module './lib/compat'

I am running a JavaScript code on Ubuntu server using node.js I got this error. 我正在使用node.js在Ubuntu服务器上运行JavaScript代码我收到此错误。

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. express模块有一个名为depd的依赖depd ,这是一个有问题的模块。

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. 文件夹lib/compat 直接属于depd ,因此没有理由丢失它。

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: 如果发生这种情况,请删除node-modules文件夹,然后运行:

npm install express

and

npm install

to reinstall all the packages listed in packages.json 重新安装packages.json中列出的所有软件包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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