找不到模块强大的 - Node.js [英] Cannot find module formidable - Node.js
问题描述
我开始使用node.j开发,我遇到了关于使用模块'formidable'的问题。
I'm starting to develop with node.j,I meet an issue regarding the using of the module 'formidable'.
我有这个错误:
错误:找不到模块'强大'
Error: Cannot find module 'formidable'
这是使用'npm ls installed'安装的模块列表:
Here is the module list installed using 'npm ls installed' :
├─┬ express@2.5.9
│ ├── connect@1.8.7
│ ├── mime@1.2.4
│ ├── mkdirp@0.3.0
│ └── qs@0.4.2
├── formidable@1.0.9
├─┬ node-inspector@0.1.10
│ ├── paperboy@0.0.3
│ └─┬ socket.io@0.8.7
│ ├── policyfile@0.0.4
│ ├── redis@0.6.7
│ └─┬ socket.io-client@0.8.7
│ ├── uglify-js@1.0.6
│ ├── websocket-client@1.0.0
│ └── xmlhttprequest@1.2.2
├─┬ npm@1.1.21
│ ├── abbrev@1.0.3
│ ├── archy@0.0.2
│ ├── block-stream@0.0.5
│ ├── chownr@0.0.1
│ ├── fstream@0.1.18
│ ├─┬ fstream-npm@0.0.6
│ │ └── fstream-ignore@0.0.5
│ ├── graceful-fs@1.1.8
│ ├── inherits@1.0.0
│ ├── ini@1.0.2
│ ├── lru-cache@1.0.5
│ ├── minimatch@0.2.2
│ ├── mkdirp@0.3.0
│ ├─┬ node-gyp@0.4.1
│ │ ├── ansi@0.0.4
│ │ └── glob@3.1.9
│ ├── node-uuid@1.3.3
│ ├── nopt@1.0.10
│ ├── proto-list@1.0.0
│ ├── read@0.0.2
│ ├── request@2.9.153
│ ├── rimraf@2.0.1
│ ├── semver@1.0.13
│ ├── slide@1.1.3
│ ├── tar@0.1.13
│ ├── uid-number@0.0.3
│ └── which@1.0.5
└─┬ socket.io@0.9.6
├── policyfile@0.0.4
├── redis@0.6.7
└─┬ socket.io-client@0.9.6
├─┬ active-x-obfuscator@0.0.1
│ └── zeparser@0.0.5
├── uglify-js@1.2.5
├─┬ ws@0.4.14
│ ├── commander@0.5.2
│ └── options@0.0.3
└── xmlhttprequest@1.2.2
我补充一点,它是唯一产生此错误的模块。
I add that it is the only module who generate this error.
另外,我不是真的理解封装了一些模块的方式,看来npm是直接在我正在使用模块安装命令的目录中安装模块,我注意到在第一次安装时已经在express / connect / module中安装了formidable。
Also, I don't really understand the way are encapsulated some module, it appears that npm is installing the module directly in the directory I'm using the module installation command, and I notice that formidable has been installed in the express/connect/ module on its first installation.
您能否提供有关模块安装树的更多信息。
感谢您的回复
Can you give me more information about the module installation tree.
Thank for your replies
干杯
推荐答案
要了解模块分辨率,请查看模块文档n ,尤其是从加载node_modules
文件夹。
To understand module resolution, have a look at the Modules documentation, especially Loading from node_modules
Folders.
例如,如果文件位于
'/ home / ry / projects / foo .js'
名为require('bar.js')
,然后节点按以下顺序查看以下位置:
For example, if the file at
'/home/ry/projects/foo.js'
calledrequire('bar.js')
, then node would look in the following locations, in this order:
-
/home/ry/projects/node_modules/bar.js
-
/home/ry/node_modules/bar.js
-
/ home / node_modules / bar .js
-
/node_modules/bar.js
/home/ry/projects/node_modules/bar.js
/home/ry/node_modules/bar.js
/home/node_modules/bar.js
/node_modules/bar.js
NPM通过将模块安装到以下来利用这一点:
NPM takes advantage of this by installing modules into:
./node_modules/{module}
所以,当你使用 npm install formidable
,它将创建并安装模块:
So, when you use npm install formidable
, it will create and install the module into:
./node_modules/formidable
但是,这意味着只有当前目录中的脚本(包括子目录)才能成功使用 require('formidable')
:
But, this means that only scripts within the current directory, including sub-directories, will succeed in using require('formidable')
:
./foo.js
./lib/bar.js
./src/baz.js
./src/sub/qux.js
但是你可以安装模块作为全球,但你必须明确要求 -g
或 - 全球
:
You can however install modules as "global," but you have to explicitly ask for it with -g
or --global
:
npm install -g formidable
然后,系统上的任何脚本都应该能够 require('formidable')
。
Then, any script on the system should be able to require('formidable')
.
对于树输出,您当前在当前目录中有5个已安装的模块:
As for the tree output, you current have 5 installed modules available from the current directory:
-
express
-
formidable
-
node-inspector
-
npm
-
socket.io
express
formidable
node-inspector
npm
socket.io
树中的其他所有内容都是名单这些模块的依赖关系及其依赖关系等,但只有这5个可用于脚本中的 require(...)
。
Everything else in the tree is a list of these modules' dependencies, and their dependencies, etc., but only these 5 are available for require(...)
within your scripts.
这篇关于找不到模块强大的 - Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!