module.js:338 在 node.js 中抛出错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28377583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
module.js:338 throw err in node.js
提问by Abdullah
I'm using ubuntu and I'm trying to run a script using nodejs and i'm getting this error.
我正在使用 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)
What is the problem? I'm in the right directory and also i tried to run it using root but nothing happens.
问题是什么?我在正确的目录中,我也尝试使用 root 运行它,但没有任何反应。
Inside server.js is
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);
A simple example just to show that node.js is working.
一个简单的例子只是为了表明 node.js 正在工作。
回答by Florian Loch
It seems like the script has an unmet 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.
脚本似乎也在使用“express”(而“merge-descriptors”实际上看起来像是“express”的依赖项)——因为这没有引发错误,一些依赖项似乎已经安装。
So you could try to install the missing ones via npm installor npm update.
因此,您可以尝试通过npm install或安装缺少的那些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
更新:根据npmjs.org,“merge-descriptors”是“express”的依赖项。查看您的堆栈跟踪表明您已在全球范围内安装了“express” - 所以您应该尝试npm update -g
If that doesn't solve your problem you should have a look at this question.
如果这不能解决您的问题,您应该看看这个问题。
回答by Andy Carr
npm update
更新
I see this when the module install order is not perfect, or multiple modules exist.
当模块安装顺序不完美或存在多个模块时,我会看到这一点。
npm update sorts this out deprecating the incorrect versions.
npm update 对此进行排序,弃用不正确的版本。
回答by Daya Kevin
Whenever you get module.js:338 throw err;try to check whether npmis installed in your machine or not.
每当您module.js:338 throw err;尝试检查是否npm已安装在您的机器中。
UserName$ npm -v
If you get the version name, then it's clear that npmis installed.
如果您获得版本名称,则很明显npm已安装。
If you don't get the version name, there is some problem with your installation or it is not installed.
如果您没有得到版本名称,则说明您的安装存在问题或未安装。
To install npm, type this command in your Terminal:
要安装npm,请在终端中键入以下命令:
UserName$ curl -0 -L http://npmjs.org/install.sh | sudo sh
Also notice I added sudobefore the sudo shcommand depending on your users permissions.
另请注意,我根据您的用户权限sudo在sudo sh命令之前添加了该命令。
回答by Vijay Chauhan
you should install merge-descriptors module. Open your terminal or command prompt and run this command:
您应该安装合并描述符模块。打开终端或命令提示符并运行以下命令:
npm install --save merge-descriptors
回答by Deepak Adhana
I also got the same issue , u should try npm install , npm update is also an option but with npm update latest npm version will be installed in your local environement . This is not desirable for global project as u may find unmet dependencies issue at global environment then.
我也遇到了同样的问题,你应该尝试 npm install , npm update 也是一个选项,但是 npm update 最新的 npm 版本将安装在你的本地环境中。这对于全局项目是不可取的,因为您可能会在全局环境中发现未满足的依赖关系问题。
I would suggest use npm install
我建议使用 npm install
回答by Karthik Dheeraj
This error occurs when module name and file name does not match. It's resolved after using the same name for module and file name. e.g.
当模块名和文件名不匹配时会发生此错误。它在对模块和文件名使用相同的名称后解决。例如
module - Hello,
File name - Hello.js

