After deploying my node.js app to another PC (in the dev machine worked perfectly) and installing all the dependencies manually, I get this error when I try to execute it:
C:\Users\myself>node app.js
module.js:340
throw err;
^
Error: Cannot find module 'xmlhttprequest'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Keystroke\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\lib\transports\index.js:5:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Keystroke\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\lib\socket.js:5:18)
But if I run
npm ls -g
It returns the list of the globally installed modules, and it includes xmlhttprequest. Then why my app is unable to find it? What am I doing wrong?
After deploying my node.js app to another PC (in the dev machine worked perfectly) and installing all the dependencies manually, I get this error when I try to execute it:
C:\Users\myself>node app.js
module.js:340
throw err;
^
Error: Cannot find module 'xmlhttprequest'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Keystroke\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\lib\transports\index.js:5:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Keystroke\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\lib\socket.js:5:18)
But if I run
npm ls -g
It returns the list of the globally installed modules, and it includes xmlhttprequest. Then why my app is unable to find it? What am I doing wrong?
Share Improve this question asked Aug 2, 2015 at 21:10 Arcadio GarciaArcadio Garcia 5491 gold badge4 silver badges17 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 19The module probably needs to be locally installed for the project as well.
Do you have a package.json file? If so, run:
npm install --save xmlhttprequest
in your repo directory next time so when your switch machines, you can run npm install
to retrieve all of the dependencies.
Some dependencies are not useful when they are globally installed on the machine.
what do you mean by
installing all the dependencies manually?
usually, we will install the dependencies by npm install --save
or npm install --save-dev
and when I need to migrate to another enviroment, I just need to clone the source code and fire npm install
from the root of the project, and it will do all the magic for me.
sometimes it will have problem if the package you are use is a c++ addon, it will failed to install that if the node version you are using is different with your dev enviroment and prod envirment, be careful. I usually use nvm
for my node version manangement, nvmw
for windows, that can save me lots of time.
npm ls
on that folder returns a list that does not contain it, so I think that is not the case – Arcadio Garcia Commented Aug 2, 2015 at 21:17require()
inxmlhttprequest
. – jfriend00 Commented Aug 2, 2015 at 22:13xmlhttprequest
module on the server. I've never had to install that module on my server when using socket.io. – jfriend00 Commented Aug 3, 2015 at 13:45