Error Nodejs cannot find installed module on Windows

0 votes

I am learning nodejs at the moment on Windows. Several modules are installed globally with npm.cmd, and nodejs failed to find the installed modules. Take jade for example,

npm install jade -g

Jade is installed in directory "C:\Program Files (x86)\nodejs\node_modules", but the following code will fail with a "Cannot find module 'jade'" error,

var jade = require('jade');

However, the code will run successfully when jade is locally installed (without -g option in npm). I don't want to use locally-installed modules, it's a waste of disk space for me. How can I make the globally-installed modules work on Windows?

Jul 15, 2020 in Node-js by kartik
• 37,520 points
4,900 views

1 answer to this question.

0 votes

Hello @kartik,

Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7/8/10), or wherever npm ends up installing the modules on your Windows flavor. To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3).

Quick solution in Windows 7+ is to just run:

rem for future
setx NODE_PATH %AppData%\npm\node_modules
rem for current session
set NODE_PATH=%AppData%\npm\node_modules

It's worth to mention that NODE_PATH is only used when importing modules in Node apps. When you want to use globally installed modules' binaries in your CLI you need to add it also to your PATH, but without node_modules part (for example %AppData%\npm in Windows 7/8/10).

Hope it works!!

Get your Node.js Certification today to become a certified expert.

Thank you!!

answered Jul 15, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

Error: Cannot find module 'ejs'

Hello @kartik, Go up one level (above app.js) ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
10,482 views
0 votes
1 answer

Error: Cannot find module 'mongodb'

Hello @kartik, The error you are getting indicates ...READ MORE

answered Oct 15, 2020 in Node-js by Niroj
• 82,840 points
13,283 views
0 votes
0 answers

Node.js Error: Cannot find module express

I have written a code for my ...READ MORE

May 9, 2022 in Node-js by Kichu
• 19,040 points
3,170 views
0 votes
1 answer

How to host MEAN stack application with Angular and nodejs on windows IIS

It's fine that you're using Angular. Be ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
1,338 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
4,190 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
3,243 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,116 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
1,028 views
0 votes
1 answer

Error:NPM global install “cannot find module”

Hello @kartik, I got this error Error: Cannot find ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
16,448 views
0 votes
1 answer

Error:Cannot find module 'xmlhttprequest'

Hello @kartik, XMLHttpRequest is a built-in object in web ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
7,196 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP