Ubuntu 16.04 - nodejs cannot find module despite being installed globally - node.js

Fresh Ubuntu 16.04 installation. Installed nodejs 10.15 according to the official instructions
# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# apt-get install nodejs
Then installed ws globally
# npm install -g ws
+ ws#6.1.3
updated 1 package in 0.374s
Then in a js file I do:
const WebSocket = require('ws');
Then run it:
# nodejs ws.js
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'ws'
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> (/var/nfs/nodes/api/arbitrage/hotbit.js:1:81)
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)
It appears the global modules are installed in /usr/lib/node_modules but apps still fail unless I manually say
export NODE_PATH=/usr/lib/node_modules
Is this a bug?

Related

Express not working with node 9.x

I have an Ubuntu box with node - v 9.5.0 and npm - 5.6.0 versions. I am trying to use expressjs (http://expressjs.com), but unable to run it. It works fine for node v 4.x.x.
$ express -h
module.js:557
throw err;
^
Error: Cannot find module 'commander'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/lib/nodejs/express-generator/bin/express:3:15)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
What is it that I am missing here?
Ubuntu's packages seem to be outdated.
Installing using apt-get node-express-generator gives this error.
Installing using npm i -g express-generator works fine.
Please try to follow the preceding steps.
Install the current version of NodeJS
Uninstall all modules with npm uninstall and rm -fr ~/.npm
Reinstall express-generator
Hope it helps.

npm cannot run in Debian: Error: Cannot find module 'node-uuid'

Not really good with this JavaScript world. Trying to install npm and I think it's broken. I'm using Debian and ran:
apt install npm.
Everything went fine but when I run npm it throws up this error
module.js:538
throw err;
^
Error: Cannot find module 'node-uuid'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/lib/nodejs/request/index.js:29:12)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
Nothing works, i can't install the node-uuid either.
I fixed this, I think there's a problem with the package on Debian repo.
I followed the instruction on Node website
https://nodejs.org/en/download/package-manager/
I have npm installed now :)

Trying To install meanjs

Iam Trying To Run meanjs with gulp
But It shows Me That!
$ gulp
module.js:327
throw err;
^
Error: Cannot find module 'vinyl'
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> (/home/bl4ckvghost/TOOLS & PROGRAMS/meanjs/node_modules/gulp-util/index.js:2:9)
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)
mongodb latest version
npm latest version
bower latest version
gulp latest version
I Want To Know How To Run Meanjs
System: Debian Jessie
Try removing your node modules and installing it again:
rm -rf ./node_modules
npm cache clean
npm install

Yeoman cannot find 'underscore.string' when using generator for web

I'm on Mac OSX Yosemite Version 10.10.3 and I'm very new to the process of developing web apps. I have bower, npm, and yeoman installed on my system, but the webapp generator keeps on returning an error when I'm trying to generate my scaffolding.
Justins-iMac-2:testapp JRS$ yo webapp
module.js:338
throw err;
^
Error: Cannot find module 'underscore.string'
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/generator-webapp/app/index.js:8: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)
at require (module.js:384:17)
Does anyone have an idea on how to resolve this issue?
There's a bug where underscore.string is set as a devDependency. I've made a PR for it.
In the mean time you can install it manually.
cd /usr/local/lib/node_modules/generator-webapp/ && npm install underscore.string
On Windows, I had to use the following command to resolve this:
npm install -g underscore.string
in any command prompt window.

Express js installation error in node

While trying to install express js by the command "npm install -g express" in cmd prompt in windows it shows the following error
module.js:340
throw err;
^
Error: Cannot find module 'express'
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> (D:\chapter3\sample-app\web-server.js:1:77)
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)
How to fix this and run a web server?
You shouldn't install express globally. cd into your project directory, then npm install express.
Global package install is meant to install command line utilities; project dependencies should be installed locally, see npm's FAQ and this blog post.

Resources