JS-libp2p Tutorial Doc "Error: Cannot find module 'libp2p'" - node.js

I wanted to start learning to use libp2p and so started up the tutorial documentation and have hit a problem right away.
The Docs: https://docs.libp2p.io/tutorials/getting-started/javascript/
Following along I got to the "Run Libp2p" header. Running the script I get the error message Error: Cannot find module 'libp2p'
When install the module with sudo npm install libp2p there was an error reading:
ursaNative bindings compilation fail. This is not an issue. Modules that depend on it will use fallbacks.
fs.js:115
throw err;
^
Error: EACCES: permission denied, open './stdout.log'
at Object.openSync (fs.js:439:3)
at Object.writeFileSync (fs.js:1190:35)
at Object.<anonymous> (/home/foss/hello-libp2p/node_modules/ursa-optional/rebuild.js:13:10)
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)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
npm WARN hello-libp2p#1.0.0 No description
npm WARN hello-libp2p#1.0.0 No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ursa-optional#0.10.1 install: `node rebuild.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ursa-optional#0.10.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-03-29T11_05_48_715Z-debug.log
`
I'm not really sure why there's a permission denied portion of the error as this was run as sudo.The problem seems to revolve around that ursa script. Although it might be optional I'm not sure. Does anyone who has worked with libp2p seen this before?
I'm using node12.16.1 and npm6.13.4 on ubuntu 19.10

Figured it out. Needed to, instead of running sudo npm i libp2p after manually installing the binaries, I had to just skip the sudo and it all works fine. This cause a problem though because I can't install modules globally now because using sudo throws the no npm command found.... I'm not too sure how to add the npm path back into the commands for sudo, or why npm is not present in sudo but is regularly.... This is strange. Will likely be resolved with other distros that natively support node v12 instead of v10. Hopefully 20.04lts will fix this.

Related

nodejs install through anaconda causing cross machine compatibility issues on linux

This problem may be hard to reproducibly describe but hopefully this works. I'm using two different machines (laptop and desktop), and following the steps below on both.
I am creating a conda environment like this:
conda create --name webdev --no-default-packages
Then I am only installing nodejs at the moment, like this:
conda install -c conda-forge nodejs
The resulting environment has only three things in it:
# Name Version Build Channel
libgcc-ng 7.2.0 hdf63c60_3 conda-forge
libstdcxx-ng 7.2.0 hdf63c60_3 conda-forge
nodejs 10.8.0 hfc679d8_1 conda-forge
Just to illustrate, I can then create a new react project like this:
create-react-app my-app
cd my-app
npm start
And the web server starts just fine and everything functions as expected. The problem I then have is that if I use my laptop to navigate into the project folder I created on my desktop and try npm start (or vice versa) I get the following error:
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '../scripts/start'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.resolve (internal/modules/cjs/helpers.js:30:19)
at Object.<anonymous> (/home/me/my-app/node_modules/.bin/react-scripts:35:25)
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)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/me/.npm/_logs/2018-11-21T01_24_45_031Z-debug.log
Strangely enough I can export the conda environment I created on my desktop, use it to create a new environment on my laptop, and will still get the error when I try to run the project I created on my desktop (and vice versa).

Stuck on npm error

I am using Homestead on Windows 10 and suddenly as I added a package ran into an issue of npm being broken, for lack of a better word.
There is some kind of problem with node-sass (included with laravel-mix), but I am not sure what.
The error is:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass#4.7.2 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass#4.7.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
This is preceeded by:
node-sass#4.7.2 install /home/vagrant/code/homestead/node_modules/node-sass
node scripts/install.js
fs.js:646
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: EINVAL: invalid argument, open '/home/vagrant/code/homestead/node_modules/node-sass/package.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.Module._extensions..json (module.js:669:20)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/vagrant/code/homestead/node_modules/node-sass/lib/extensions.js:7:9)
at Module._compile (module.js:652:30)
I have tried deleting node_modules folder to build it from scratch. It also runs into a symlink error, so I am running npm install with the --no-bin-links option
I am not sure what else to do. I have found nothing on Google so far to help me.
This is a snippet from the logs:
1975 verbose lifecycle node-sass#4.7.2~install: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vagrant/code/homestead/node_modules/node-sass/node_modules/.bin:/home/vagrant/code/homestead/node_modules/.bin:/home/vagrant/.composer/vendor/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
1976 verbose lifecycle node-sass#4.7.2~install: CWD: /home/vagrant/code/homestead/node_modules/node-sass
1977 silly lifecycle node-sass#4.7.2~install: Args: [ '-c', 'node scripts/install.js' ]
1978 silly lifecycle node-sass#4.7.2~install: Returned: code: 1 signal: null
1979 info lifecycle node-sass#4.7.2~install: Failed to exec install script
To add:
I have also cleared npm cache (verified and even force cleared), provisioned Homestead several times. This is also actually a new box since the last one refused to come up so I replaced it completely. One of the more recent commands I ran was:
npm audit fix
Could that have broken it? I ran the install on my Windows host on the same folder and it worked without issues. After that it seems the install also works on Homestead. There are a lot of rollbacks but no specific errors anymore. I am still however at a loss as to what went wrong. I should not have to use a Windows machine to correct Linux mistakes.
And to edit again: while running install no longer introduced any errors, I still cannot run it. It doesn't run on Homestead/Linux nor on Windows. So I am still stuck.

npm install: Error : Cannot find module 'tough-cookie'

I have removed and reinstalled node.js many times
> node -v
4.5.0
> npm -v
3.3.6
Once I run the command npm install request I get the following error :
Error: Cannot find module 'tough-cookie'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Generic User\AppData\Roaming\npm\node_modules\npm\node_modules\request\lib\cookies.js:3:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Generic User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "request"
npm ERR! node v4.5.0
npm ERR! npm v3.3.6
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'tough-cookie'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
You probably will tell me to run
> npm update -g npm
I get the same error for this command too.
It looks like your version 3 npm install is broken, for some reason. It'd be interesting to know whether this path exists:
C:\Users\Generic User\AppData\Roaming\npm\node_modules\npm\node_modules\request\node_modules\tough-cookie
and whether it contains a valid package, etc.
With your npm v 3 install, broken, none of the npm install or update commands will work (as they'll need the request module). However, you might be able to roll back npm - as version 4.5.0 of Node.js installs npm version 2.15.9 and it will still be there:
> npm uninstall -g npm
That should leave you with:
> npm -v
2.15.9
Before re-installing npm v 3, clear the cache:
> npm cache clear
> npm install -g npm
However, before you re-install version npm v 3, it would be interesting to see if you are able to install request with npm v 2.
In my case it was a .lock file that caused this error, deleting the file fixed it. Same problem and solution was reported here: https://github.com/sass/node-sass/issues/2019
Is there a package.json file in the folder you are running node from?
If there is a package.json, then running :
npm install request
will not have the desired effect, in fact npm will just try and install whatever module is described in package.json
Have you tried npm install tough-cookie
it has worked for me
its browser issue ... please try to open it in chrome incognito windows or firefox private window and delete cookies

NPM broken mime-db missing

I had to reinstall Nodejs on my Macbook when I ran into an issue with npm.
No matter what I did I always got this output:
$ npm
Error: Cannot find module 'mime-db'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/node_modules/form-data/node_modules/mime-types/index.js:2:10)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'mime-db'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
I did not understand who this was happening. So I installed it one more time in hope that it would be fixed. No luck.
I did fix it after a wasting to much time. That is why I put it on here so that if anybody may walk into the same problem they solve it sooner then I did.
I used following command on node command prompt
npm install mime-db
It gave me warning: unmet dependency that it requires version 1.12 of mime-db, but it will download version 1.21 of mime-db
i ran the same command again i.e.
npm install mime-db
It solved my issue
Good Luck.
Another solution:
I was trying out something else, then I upgraded node package, downloading from node website and installing it, then i did not face this issue.
Thank you
After looking in the repo of mime-db and saw that I was missing this file in the module that was installed with the pkg. I added this file and now it works.
Good luck!
I deleted mime-db from the node_modules folder. Then I ran
npm i mime-db
That solved my problem.

node-sass install failing on Jenkins

I'm trying to set up Jenkins to run Gulp but it keeps failing while attempting to install node-sass (a dependency of the gulp-sass plugin).
The issue seems to be that node is not finding a script file during install. I verified that script does actually exist in the project repository. When I pull my repo locally on the server and install it, it installs without a problem. That makes me think it's a Jenkins related environment issue.
Here's the error output:
> node-sass#2.1.1 install /root/.jenkins/jobs/odyssey-frontend/workspace/node_modules/gulp-sass/node_modules/node-sass
> node scripts/install.js
module.js:338
throw err;
^
Error: Cannot find module '/root/.jenkins/jobs/odyssey-frontend/workspace/node_modules/gulp-sass/node_modules/node-sass/scripts/install.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
npm ERR! Linux 3.14.35-28.38.amzn1.x86_64
npm ERR! argv "node" "/home/ec2-user/.linuxbrew/bin/npm" "install" "--production"
npm ERR! node v0.12.2
npm ERR! npm v2.7.6
npm ERR! code ELIFECYCLE
npm ERR! node-sass#2.1.1 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass#2.1.1 install script 'node scripts/install.js'.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls node-sass
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /root/.jenkins/jobs/odyssey-frontend/workspace/npm-debug.log
module.js:338
throw err;
^
Error: Cannot find module 'gulp-sass'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/root/.jenkins/jobs/odyssey-frontend/workspace/gulpfile.js:11:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The Linux distribution is Amazon Linux AMI, Fedora-like. Trying to install node-sass ^2.0.1 via gulp-sass ^1.3.3.
I just tried the updated gulp-sass 2.0.0 with node-sass 3.0.0 and still have the same issue.
I removed all node-sass dependencies and it builds successfully now. So its really just that package; all other node packages install successfully.
I posted this on the Github project where it was answered: https://github.com/sass/node-sass/issues/941#issuecomment-100414516
Jenkins seems to run everything as sudo when building. NPM, as a security feature, won't run install scripts as sudo, hence the error. Adding a --unsafe-perm flag to the install script gets by this issue.

Resources