Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS cannot find module 'xml2js' (Windows)

OS: Windows 7 64-bit

Need to do parsing xml-file using Node.js.

Using a library for parsing xml2js.

Xml2js installed using the command "npm install xml2js".


However, if you run the code:

var fs = require ('fs'), xml2js = require ('xml2js'); 

var parser = new xml2js.Parser (); 
fs.readFile ('<path to the xml-file>', function (err, data) {
     parser.parseString (data, function (err, result) {
         console.dir (result); 
         console.log ('Done'); 
     }); 
});

an error:

module.js:340
    throw err;
          ^
Error: Cannot find module 'xml2js'
    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> (<путь до js-файла>:3:14)
    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 Function.Module.runMain (module.js:497:10)

Tell me, please, how to solve the problem?

like image 888
someUserMain Avatar asked May 13 '14 07:05

someUserMain


1 Answers

I was also facing the same issue. Here's what I did:

Install the module using following:

$ npm install -g *module_name*

Then go to any parent dir of your project dir (it can be project dir itself) and run the following command:

$ npm link *module_name*

like image 66
Vishwanath Rawat Avatar answered Sep 29 '22 04:09

Vishwanath Rawat