I am working on Debian Stable Linux which is updated and working very well.
I have installed a compute-pcorr package globally with following npm command:
$ sudo npm install compute-pcorr -g
It is listed with following npm command:
$ npm list -g --depth=0
/usr/local/lib
├── [email protected]
└── [email protected]
I am now trying following code demo code from its homepage:
var pcorr = require( '[email protected]' );
var x = [ 1, 2, 3, 4, 5 ];
var y = [ 5, 4, 3, 2, 1 ];
var mat = pcorr( x, y );
Console.log("Correlation Matrix: "+ mat)
However, when I run above code, I get error:
$ node compute_pcorr_usage.js
internal/modules/cjs/loader.js:818
throw err;
^
Error: Cannot find module '[email protected]'
Following in code is also not working:
var pcorr = require( 'compute-pcorr' );
I also tried to reinstall package with following command, but error persists:
sudo npm install compute-pcorr -g --save
Where is the problem and how can it be solved?
2
Answers
This issue happens when the library is not installed locally.
Try installing locally in your directory with the command
npm install compute-pcorr
There’s no need of installing globally via
-g
The problem seems to be with the way you are requiring the
compute-pcorr
module in your code. Instead of specifying the version in the require statement, you should simply userequire('compute-pcorr')
.Here’s the corrected code:
By removing the version number from the require statement,
Node.js
will search for the installed module without considering a specific version.