node express module not found when installed globally - node.js

my node app directory sits at /usr/node/express-test/app.js
I followed this thread to set up my environment so that I can have a freelancer come in and install npm packages globally on our server without having to have access to sudo.
How to npm install globally without root
I've checked my NODE_PATH... looks okay to me.
echo $NODE_PATH
/usr/node/.npm-packages/lib/node_modules
However, the error I see when I try to run my app.js appears to be that it cannot find my globally installed express module
app.js
/usr/node/express-test# node app.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /usr/node/express-test/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/usr/node/express-test/app.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/node/express-test/app.js' ]
}
Ideas to what the problem may be please?

My suggestions on this:
First of all, do not install express or any other packages as global put packages in the package.json and run npm install or do npm install --save express to save the packages to local node_modules and list it in package.json, track that package.json & package-lock.json in git so that it can be used in other places, this way if you shift to some new VM you don't need to install packages as global again, you can just do npm install or better npm ci and it's all work.
Secondly, if you still want to use global packages go to /usr/node/.npm-packages/lib/node_modules and see if you can find express folder there

Related

I got following error while developing in MEAN stack : Cannot find module 'mongojs'

I ran command: node server in bash on Ubuntu and below is the error I got:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'mongojs'
Require stack:
- /home/nishil/Documents/contactListApp/server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/nishil/Documents/contactListApp/server.js:5:15)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/nishil/Documents/contactListApp/server.js' ]
}
How can I resolve this error?
Please check in your package.json file if mongojs is installed or not.
If it is then remove package-lock.json and remove node_modules folder and install node modules again by npm i.
If mongojs is not installed then you can do that using npm i mongojs command
But i would suggest please change your package from mongojs to mongodb https://www.npmjs.com/package/mongodb
As mongojs is seems outdated its not updated since last 3 years it has 27 open issues since very long.
Let me know if this solutions works for you..
If you want to use mongojs or any other module, please make sure it's there in package.json and you have run yarn install or npm install in that directory containing the package.json. If the problem still persists, try deleting the node_modules folder in this directory and try running yarn install or npm install again.

"I got an error after reinstalling nodejs"

node:internal/modules/cjs/loader:1161 return process.dlopen(module,
path.toNamespacedPath(filename));
^
Error: The module '\?\G:\Discord
bot\Bot\ZackyBot\node_modules\canvas\build\Release\canvas.node' was
compiled against a different Node.js version using NODE_MODULE_VERSION
83. This version of Node.js requires NODE_MODULE_VERSION 88. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1161:18)
at Module.load (node:internal/modules/cjs/loader:967:32)
at Function.Module._load (node:internal/modules/cjs/loader:807:14)
at Module.require (node:internal/modules/cjs/loader:991:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object. (G:\Discord bot\Bot\ZackyBot\node_modules\canvas\lib\bindings.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1102:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
at Module.load (node:internal/modules/cjs/loader:967:32)
at Function.Module._load (node:internal/modules/cjs/loader:807:14)
at Module.require (node:internal/modules/cjs/loader:991:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object. (G:\Discord bot\Bot\ZackyBot\node_modules\canvas\lib\canvas.js:9:18)
at Module._compile (node:internal/modules/cjs/loader:1102:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
at Module.load (node:internal/modules/cjs/loader:967:32) { code: 'ERR_DLOPEN_FAILED' }
It seems like you installed a newer version of NodeJS than earlier. But you did not compile your project ZackyBot's node modules using the current version of the NodeJS you installed.
I would suggest you go to your project directory and clean all your node modules. Then reinstall them again. Follow the steps below:
Delete node_modules directory inside ZackyBot directory
Execute npm install command on a terminal from ZackyBot directory
Since you updated your nodeJS version to a newer one, you need to update your canvas too.
run npm install canvas and you should be good to go.
This might be due to improper installation of node modules and can occur due to poor network conditions.
Solved this issue by deleting the nodemodules folder and doing a clean installation of node modules files by running "npm install".

NPM Fails install of bcrypt on ElasticBeanstalk

I have everything running fine locally here on OSX and I am trying to deploy this to aws elasticbeanstalk. During the deployment process I was getting an error such as the following
bcrypt#1.0.3 install /tmp/deployment/application/node_modules/bcrypt
node-pre-gyp install --fallback-to-build
module.js:471
throw err;
^
Error: Cannot find module '../'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous>
(/tmp/deployment/application/node_modules/.bin/node-pre-gyp:15:20)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
I have read that this appears to be an issue with npm install and that I should add bcrypt directly to my package.json file for a dependency and I have done just that.
I was able to replicate the issue locally by deleting my node_modules folder and trying to run npm install without having bcrypt as a dependency. I then deleted the node_modules folder again and added bcrypt as a direct dependency and npm install worked just fine.
However I cannot seem to get this to resolve itself on elasticbeanstalk. When I ssh into the instance there is no node or npm in the path, I am not sure where they are installed to on ElasticBeanstalk. I did find that the deployment is under /tmp/deployment/application and I tried to remove the node_modules directory and deploying again however that did not solve the issue either.
You might wanna make sure the beanstalk instance has Python 2.x installed as BCrypt relies on this in order for it to work.
Also, beanstalk apps are installed in the following path: /var/app/current

Getting error: Cannot find module 'errno' running node script

I've just installed a fresh copy of Ubuntu 15.10, node 4.2.2 and npm 2.14.7 (with nvm) on a new machine. I have installed webpack and webpack-dev-server globally and installed my project dependencies with npm i.
Now when I try to run my node server I get the following errors:
module.js:339
throw err;
^
Error: Cannot find module 'errno'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:7:14)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
Any suggestions please?
Node.js searches for modules in the ./node_modules/ directory in the path where the program is.
For example if you script is here /home/user/scripts/somescript.js you should have /home/user/scripts/node_modules/.
Just do npm install errno in here /home/user/scripts/.
It seems that something had gone wrong with my npm install and my project dependencies were only partly installed. Just running npm install again didn't fix it. I did an npm cache clean, removed my node_modules directory and then ran npm install again. The problem was then resolved.

node.js returns "Cannot find module 'lockit-mongodb-adapter'"

I am going through my first node.js project. I've installed lockit , have a app.js file, and when I try to run it I get this error
module.js:340
throw err;
^ Error: Cannot find module 'lockit-mongodb-adapter'
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 new module.exports (C:\Users\xx\Documents\mailer\index.js:38:44)
at Object.<anonymous> (C:\Users\xx\Documents\mailer\examples\mongodb\app. js:32: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)
I am quite certain I have lockit-mongodb-adapter installed.
You need to install the module. Cd to the root of your app directory and run this command and make sure lockit-mongodb-adapter is in your node modules directory.
npm install lockit-mongodb-adapter
Another thing you can do if you are certain it is installed is double check to see what is installed by running this command:
npm list
And this one to see what is installed globally:
npm list -g
Update:
I was able to reproduce the issue you where having. And to resolve it I deleted the module from the node moules directory. And re-installed with the following command:
npm install lockit-mongodb-adapter -save
It now shows up in npm list with no issues:

Resources