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?

#1
After pulling down a module from GitHub and following the instructions to build it, I try pulling it into an existing project using:

> npm install ../faye

This appears to do the trick:

> npm list
/home/dave/src/server
└─┬ [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

But Node.js can't find the module:

> node app.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'faye'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous> (/home/dave/src/server/app.js:2:12)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)

I really want to understand what is going on here, but I'm at a bit of a loss as to where to look next. Any suggestions?
Reply

#2
I was trying to publish my own package and then include it in another project. I had that issue because of how I've built the first module. Im using ES2015 export to create the module, e.g lets say the module looks like that:

export default function(who = 'world'){
return `Hello ${who}`;
}

After compiled with Babel and before been published:

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function () {
var who = arguments.length <= 0 || arguments[0] === undefined ? 'world' : arguments[0];


return 'Hello ' + who;
};

So after `npm install module-name` in another project (none ES2015) i had to do


`var hello = require('module-name').default;`

To actually got the package imported.

Hope that helps!
Reply

#3
Remove your `node_module` root folder from your project(eg: `myApp`).
Go to `myApp` folder and then type below command from terminal

>myApp>npm install
It will install all the dependency modules required for your project.
Reply

#4
I experienced this error yesterday. Took me a while to realise that the `main` entry in `package.json` was pointing to a file that I'd moved. Once I updated that the error disappeared and the package worked.
Reply

#5
PRO TIP:

This error happened to me, while fighting fatigue and mild illness, because I typed `node blah` instead of `npm blah`.

The error message received wasn't angry enough to alert me to my own folly!
Reply

#6
First of all, yes, a part of my answer definitely is helpful to solve the **error** that is posted by OP. Secondly, after trying the below step, I faced a couple of other errors, and so, have written the solution of those too.

***(Psst! I am not sure if I've successfully helped in solving the above error, or if I've broken some rule or format of answering, but I faced the above error and some others and it took much time for me to find the proper solutions for those errors. I'm writing the complete solution because in case, if someone else also faces these errors, then he'll hopefully get a solution here.)***

So adding to, and elaborating the answer provided by [PrashanthiDevi][1], and also adding my personal experience, here it is:

I am new to the whole e2e and unit tests part. I started looking into this part from [Protractor][2]. Now I already had the files in which tests were written, but I had to run the tests.

I had already installed all the required softwares and tools, but when I initially ran the code for running the tests, `gulp itest`, I got this **'Cannot find module' Error**. After going through many different questions on SO, I found one answer that I thought could help getting a solution.

The person had suggested to run the command `npm install` in my project folder.

The **reason** for doing this was to update the ***node-modules*** folder, inside our project folder, with all the required and necessary files and dependencies.

*(The below part maybe irrelevant with this question, but might be helpful if anyone came across the same situation that I faced.)*

The above step surely **solved** my previous error, but threw a new one! This time the error being **`Could not find chromedriver at '..\node_modules\protractor\selenium\chromedriver'`**.

However, the solution of this error was pretty silly (and funny) to me. I already had the chromedriver file in my **selenium** folder. But, turns out that the above error was coming because my **chromedriver** files were inside ***selenium*** folder and **not inside** ***chromedriver*** folder. So, creating a **chromedriver** folder and copying the chromedriver files there solved my problem!

*Also, for the **error: Timed out waiting for the WebDriver Server**, you could add this **line of code** to **conf.js** file inside `exports.config{}`:*

`seleniumAddress: 'http://localhost:8080/'`

Hope this helps!


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#7
I had a very similar issue. Removing the entire `node_modules` folder and re-installing worked for me:

rm -rf node_modules
npm install
Reply

#8
This happens when a first [npm][1] install has crashed for some reason (SIGINT of npm), or that the delay was too long, or data is corrupted.
Trying an npm install again won't save the problem.

Something got wrong on the npm first check, so the best choice is to remove the file and to restart npm install.

[1]:

[To see links please register here]

Reply

#9
If you use nvm, check that existing node_modules that are bindings to other libraries are compiled for the correct Node.js version.

I was having the same error. The reason was the following: We use nvm since we're running two apps on a server, one requires Node.js 5.6 because it uses node-gd (which doesn't run on Node.js 6 for now), the other requires Node.js 6. Node.js 6 is the [apt-get][1] installation.

Also we use the pm2 tool to deploy.

So, the default setup is that the pm2 process starts when nvm is not in effect, so it uses the apt-get installation of Node.js (version 6). So the main pm2 daemon starts with Node.js 6. If I run applications in fork mode they start in separate processes and nvm settings are in effect. When I run applications in cluster mode - they inherit the non-nvm environment.

So when I tried to switch to the cluster mode the application failed to start because the bindings compiled for 5.6 fail with this message.

I've fixed that by restarting pm2 when nvm setings are in effect. Also startup scripts should be fixed.

[1]:

[To see links please register here]

Reply

#10
Encountered this problem while using **`webpack`** with **`webpack-dev-middleware`**.

Had turned a **single file** into a **folder**.

The watcher seemed to not see the new folder and the module was now missing.

Fixed by restarting the process.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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