module.js:338在node.js中抛出错误

Abd*_*lah 13 node.js

我正在使用ubuntu,我正在尝试使用nodejs运行脚本,我收到此错误.

/home/bebz/Documents/test# node server.js
module.js:338
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)
Run Code Online (Sandbox Code Playgroud)

问题是什么?我在正确的目录中,我也尝试使用root运行它,但没有任何反应.

在server.js里面是

// 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);
Run Code Online (Sandbox Code Playgroud)

一个简单的例子,只是为了表明node.js正在运行.

Flo*_*och 27

看起来该脚本具有未满足的依赖性 - 这意味着您必须首先安装模块"merge-descriptors".

似乎脚本使用"express"(和"merge-descriptors"实际上看起来像是"express"的依赖项) - 因为这并没有抛出错误,似乎已经安装了一些依赖项.

所以你可以尝试通过npm install或安装缺少的npm update.

更新:根据npmjs.org "merge-descriptors"是"express"的依赖项.查看堆栈跟踪显示您已全局安装"express" - 因此您应该尝试npm update -g

如果这不能解决您的问题,您应该看看这个问题.

  • 我使用`npm update`它现在正在工作.非常感谢! (2认同)