Unable to find a formidable module - Node.js

I'm starting to develop using node.j, I come across a question about using the formidable module.

I have this error:

Error: cannot find the formidable module

Here is the list of modules installed with "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 this is the only module that generates this error.

In addition, I really don’t understand how any module is encapsulated, it seems that npm installs the module directly in the directory in which I use the module installation command, and I notice that the formidable was installed in express / connect / module during the first installation .

Can you give me more information about the module installation tree.
thank you for your responses

Greetings

+6
source share
2 answers

To understand module resolution, see Module Documentation , especially Downloading from the node_modules Folders .

For example, if the file in '/home/ry/projects/foo.js' is called require('bar.js') , then the node will look in the following places in the following order:

  • /home/ry/projects/node_modules/bar.js
  • /home/ry/node_modules/bar.js
  • /home/node_modules/bar.js
  • /node_modules/bar.js

NPM uses this by installing modules in:

 ./node_modules/{module} 

So, when you use npm install formidable , it will create and install the module in:

 ./node_modules/formidable 

But this means that only scripts in the current directory, including subdirectories, will succeed in using require('formidable') :

 ./foo.js ./lib/bar.js ./src/baz.js ./src/sub/qux.js 

However, you can install modules as "global", but you must explicitly request it with -g or --global :

 npm install -g formidable 

Then any script on the system must be able to require('formidable') .


As for tree output, you have 5 installed modules available from the current directory:

  • express
  • formidable
  • node-inspector
  • npm
  • socket.io

Everything else in the tree is a list of the dependencies of these modules, their dependencies, etc., but only these 5 are available for require(...) inside your scripts.

+3
source

The accepted answer seems very comprehensive and correct, but it worked for me:

 npm install -d 

d means dependencies (I think)

+5
source

Source: https://habr.com/ru/post/915001/


All Articles