Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 482 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I resolve "Cannot find module" error using Node.js?

#11
Just found an unusual scenario that may be of use to someone and is sort of a red herring.

I was also getting the Cannot Find Module error but oddly everything worked perfectly in my local (Mac hosted) Node.js environment. This problem only appeared when the code was deployed on our Linux server.

Well... it turned out to be a typo that (apparently) the Mac based Node.js installation was perfectly happy to ignore.

The include looked like this:

var S3Uploader = require('./S3Uploader.class');

But the actual file was called "s3Uploader.class.js"

Notice the casing difference in the 's' vs. 'S' between the code and the filename.

So - in the odd chance that none of the other solutions here are solving your problem, triple check that you're not mis-casing the characters in your included filename! :)

and DUH!
Reply

#12
npm install --save module_name

For example, if the error is:

> { [Error: Cannot find module '/root/.npm/form-data'] code: 'MODULE_NOT_FOUND' }

then you can resolve this issue by executing the command `npm install --save form-data`.
Reply

#13
This error can be encountered if you are `require`ing a module that has a missing or incorrect `main` field in its package.json. Though the module itself is installed, npm/node has to use a single .js file as an entrypoint to your module. If the `main` field is not there, it defaults to looking for `index.js` in your module's folder. If your module's main file is *not* called index.js, it won't be able to `require` it.

Discovered while turning a `browserify`-based module into a CommonJS `require`-able module; `browserify` didn't care about the missing `main` field, and so the error had gone unnoticed.
Reply

#14
I can add one more place to check; the package that I was trying to use was another one of my own packages that I had published to a private NPM repo. I had forgotten to configure the 'main' property in the package.json properly. So, the package was there in the node_modules folder of the consuming package, but I was getting "cannot find module". Took me a few minutes to realise my blunder. :-(
Reply

#15
Specify the path to the restler folder, which will be inside node_modules folder like : var rest = require('./node_modules/restler');

This worked for me.
Reply

#16
In my case I had `UNMET PEER DEPENDENCY redux@^3.0.0` causing this error message, see all of them and install missing modules again using --save

npm install redux --save
Reply

#17
Change the directory and point to your current project folder and then "npm install".
.

This will install all dependencies and modules into your project folder.
Reply

#18
Maybe like me you set 'view engine' in express to an engine that doesn't exist, or tried to use an unregistered templating engine.
Make sure that you use:
`
app.engine('engine name',engine)
app.set('view engine','engine name')
`
Reply

#19
Check if the enviroment variable NODE_PATH is set correctly and pointing to the node_modules path. nodejs uses this variable to search for the libraries
Reply

#20
For TypeScript users, if you are importing a built-in Node module (such as `http`, `path` or `url`) and you are getting an error such as `"Cannot find module "x"` then the error can be fixed by running

npm install @types/node --save-dev

The command will import the NodeJS TypeScript definitions into your project, allowing you to use Node's built-in modules.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through