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 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 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.
Related
Hello I am new in a nodejs and when I run any file in command prompt like:-
C:\demoData>node demo.js
I get error li9ke this
module.js:327
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\demoData\shahzad.js:1:77)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
I did R&D and get the solution
npm install express
And my Problem has solved using this. But Why I required this I have already express folder globally.this path
C:\Users\broswire\AppData\Roaming\npm\node_modules;
I want to use this node_modules, I don't want locally node_modules.
Node encourages using locally installed modules. Generally, using modules installed with npm install --global or npm install -g should be reserved for cli tools and things used systemwide. So to use express in a project, it is recommended to npm install express in that directory. It is also useful to add a package.json file to save the versions of your dependencies. Then you can just navigate to your project and run npm install and it will install the required dependencies.
I am trying to create my first sails app and I've followed the steps on the sails getting started (http://sailsjs.org/get-started). But when i try to do a sails lift, i get the following error:
(node:11291) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
module.js:442
throw err;
^
Error: Cannot find module 'express/node_modules/cookie'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/master/Desktop/Developer/NodeJS/HelloSails/node_modules/sails/lib/hooks/session/index.js:9:12)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /Users/master/Desktop/Developer/NodeJS/HelloSails/node_modules/sails/lib/app/configuration/index.js:54:28
at Function.reduce (/Users/master/Desktop/Developer/NodeJS/HelloSails/node_modules/sails/node_modules/lodash/dist/lodash.js:3735:25)
at Configuration.defaultConfig (/Users/master/Desktop/Developer/NodeJS/HelloSails/node_modules/sails/lib/app/configuration/index.js:53:18)
at Configuration.bound [as defaults] (/Users/master/Desktop/Developer/NodeJS/HelloSails/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
I tried manually removing the 'node_modules' folder, inserting express as a dependency in my package.json and running 'npm install', but that did not work.
Im running Node v6.2.2 Sail v0.10.5 and NPM v3.10.6
What am i missing here?
update sails version to latest, it is issue of npm structure, old version use tree level dependency while new version use same level structure
sails upgrade version
It's a dependency issue with npm, this worked for me when I had the issue.
npm -g install npm#latest
I am following this https://developers.facebook.com/docs/messenger-platform/quickstart tutorial to add a web hook.
It's written to use this app https://github.com/fbsamples/messenger-platform-samples
that app is a node js app.
in the app.js, there is this:
const
bodyParser = require('body-parser'),
config = require('config'),
crypto = require('crypto'),
express = require('express'),
https = require('https'),
request = require('request');
when i run the app like this:
node app.js
i get the following error:
module.js:327
throw err;
^
Error: Cannot find module 'body-parser'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\MyApps\messe
nger-platform-samples-master\node\app.js:14:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
how can I solve it please ?
Open terminal (or windows command line), go to messenger-platform-samples/node directory and install messenger-platform-samples by running this command:
npm install
after that you can run the app:
node app.js
First run npm install and this will rectify all errors
Run this command first
npm install -g body-parser
then create const bodyParser = require('body-parser')
Error: Cannot find module 'websocket-server'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (D:\Rahul\hubServer\togetherjs-develop\togetherjs-develop\hub\websocket-compat.js:27:28)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
That means you have not installed that module. To do this do
npm install websocket-server
Usually instead of doing this manually you will have a package.json file and you can install all the modules by doing npm install
I'd you want to save websocket-server to the package run this command:
npm install websocket-server --save
Remember to do npm install __ in the directory of where your site is. Otherwise node won't find it.
I have node.js install on linux, and file.js. In the same directory I have node_modules directory with lru-cache module.
file.js does the following:
var lrucache = require('lru-cache')
But when I run it, it raises the following error:
Error: Cannot find module 'lru-cache'
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> (/opt/file.js:58:12)
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 Function.Module.runMain (module.js:497:10)
What is the problem? the same is working in other linux system.
Please try:
rm -rf node_modules && npm cache clean && npm install
Sometimes npm has an issue and the dependency lru-cache may not get properly installed.
Most node modules will have their own set of package dependencies so you cannot just copy the folder or clone the repository without making sure you are satisfying the module's dependencies.
The easiest way would be using npm for ALL package installations.
After you have run npm init in your project's root directory to set up your package.json use
$ npm install modulename --save
to install a package AND its dependencies. You can now safely use
var module = require('modulename');
throughout your whole project.
In case you cannot install your package via npm make sure all of its dependencies are installed as well by navigating to node_modules/modulename and running npm install (no arguments) here. This will install all dependencies that are listed in the modules own package.json file.