'Cannot find module but is already installed in current Project (xml-js, Windows)

I'm actually working in a cross platform Project (Nodejs Package), all time I working under Linux platform, and sometimes I run the package on windows to test it. But for some reason in Windows I get "Cannot find module" error. That problem happen with 'xml-js' module, but the real strange situation happens when I init new clean package with 'xml-js' module installation. When I make a simple script that import the module, the error not appears. I really so confused and frustrated, because this only happens in Windows platform.

In addition, I tried by globally installation of package and obviously also locally installation of 'xml-js' module. Is not a syntax error, because in Linux the package working perfectly.

Previously I have working with "xml2js", and the same error been occurred. So I don't have any idea of the real problem.

If anyone wants to see the error, it's here …

Error: Cannot find module 'xml-js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\Users\eduar\my-package\lib\src\tools.js:2:15)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

IMPORTANT EDIT: Ok, by testing package I found a interesting thing. When I import the module in the root of project, this is correctly imported. I test my own package by other "clean" package creation. In the last I install my project (package) for testing but returns an error when my project tries to import the 'xml-js' module. I don't know if this error disappears once the package be uploaded in npmjs.com, but I don't want to upload a incomplete project only to test this problem.



Solution 1:[1]

Try below command

npm i xml-js --save

then run again

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shurvir Mori