2014-06-22 47 views
1

在Node.js的,我试图用强大的模块,但我总是得到错误的错误找不到模块“node_modules /强大的”

**Error: Cannot find module 'node_modules/formidable'** 

详情:

C:\Program Files\nodejs>node E:\NODE_JS\App1\index.js 

module.js:340 
    throw err; 
     ^
Error: Cannot find module 'node_modules/formidable' 
    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> (E:\NODE_JS\App1\requestHandlers.js:4:18) 
    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) 

我曾尝试使用以下命令以两种方式安装模块:

npm install formidable 
npm install -g formidable 

而当我运行命令(上面两个)安装formid能结果是

C:\Users\Piccaza>npm install formidable 
[email protected] node_modules\formidable 

C:\Users\Piccaza>npm install -g formidable 
[email protected] C:\Users\Piccaza\AppData\Roaming\npm\node_modules\formidable 

我已经安装在位置C:\Program Files\nodejs

和的NodeJS我的项目的位置是E:\NODE_JS\App1

+0

你可以发布你的'index.js'文件的内容吗?它看起来像你需要“node_modules /强大”而不是“强大” – dylants

+0

其实我需要从我的requestHandler.js文件。 // var formidable = require(“node_modules/formidable”); // var formidable = require(“formidable”); 我尝试了两种方式。 – Dipak

回答

2

当您通过npm install安装一个软件包,你不必要求与文件文件的完整路径。相反,只需要包装。

因此,而不是使用:

var formidable = require("node_modules/formidable"); 

变化,而不是使用方法:

var formidable = require("formidable"); 

作为一个说明,如果你需要的本地文件,你需要指定这些文件的完整路径。 You can view the algorithm that is used to lookup files here.