Abdullah Abdullah - 1 year ago 95
Node.js Question

module.js:338 throw err in node.js

I'm using ubuntu and I'm trying to run a script using nodejs and i'm getting this error.

/home/bebz/Documents/test# node server.js
throw err;
Error: Cannot find module 'merge-descriptors'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/bebz/node_modules/express/lib/express.js:6:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)

What is the problem? I'm in the right directory and also i tried to run it using root but nothing happens.

Inside server.js is

// get dependencies
var app = require("express")();

// handle request and response
app.get("/", function(req, res) {
res.send({name:"Hello Wolrd"});

// initializing a port
app.listen( 5000);

A simple example just to show that node.js is working.


It seems like the script has an unmeet dependency - meaning you have to install the module "merge-descriptors" first.

It also seems like the script is using "express" (and "merge-descriptors" actually looks like a dependency of "express") - because this didn't throw an error some dependencies seem to be installed already.

So you could try to install the missing ones via npm install or npm update.

Update: According to npmjs.org "merge-descriptors" is an dependency of "express". Looking at your stacktrace shows that you have "express" installed globally - so you should try npm update -g

If that doesn't solve your problem you should have a look at this question.