Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module formidable - Node.js

I'm starting to develop with node.j,I meet an issue regarding the using of the module 'formidable'.

I have this error:

Error: Cannot find module 'formidable'

Here is the module list installed using 'npm ls installed' :

├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ └─┬ [email protected] 
│   ├── [email protected] 
│   ├── [email protected] 
│   └─┬ [email protected] 
│     ├── [email protected] 
│     ├── [email protected] 
│     └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
└─┬ [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  └─┬ [email protected] 
    ├─┬ [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ ├── [email protected] 
    │ └── [email protected] 
    └── [email protected] 

I add that it is the only module who generate this error.

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

Cheers

like image 787
bengo Avatar asked May 06 '12 02:05

bengo


People also ask

What is formidable node JS?

Formidable is a Node. js module for parsing form data, especially file uploads.

Can not find Module Express?

To solve the error "Cannot find module 'express'", install the package by running the command npm install express in the root directory of your project. If you don't have a package. json file, create one by running npm init -y . The error occurs when we try to import the express package without installing it.

How do I get rid of formidable?

If you would like to uninstall Formidable and delete all forms, entries, views, styles, and all other Formidable data, you may go to Formidable → Global Settings → Miscellaneous and check the box to 'Uninstall Formidable Forms and permanently delete all data.


2 Answers

The accepted answer looks very comprehensive and correct, but this worked for me:

npm install -d

d stands for dependencies (I think)

like image 187
captainclam Avatar answered Oct 04 '22 01:10

captainclam


To understand module resolution, have a look at the Modules documentation, especially Loading from node_modules Folders.

For example, if the file at '/home/ry/projects/foo.js' called require('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

NPM takes advantage of this by installing modules into:

./node_modules/{module}

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

./node_modules/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

You can however install modules as "global," but you have to explicitly ask for it with -g or --global:

npm install -g formidable

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


As for the tree output, you current 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 these modules' dependencies, and their dependencies, etc., but only these 5 are available for require(...) within your scripts.

like image 26
Jonathan Lonowski Avatar answered Oct 04 '22 01:10

Jonathan Lonowski