Cannot find module 'mongodb/node_modules/bson' - javascript

These are the statments i got after running the grunt serve command from the directory sangam
C:\Users\Rohit\Documents\GitHub\sangam>grunt serve
Running "serve" task
Running "clean:server" (clean) task
Running "env:all" (env) task
Running "concurrent:server" (concurrent) task
Running "injector:scripts" (injector) task
Missing option `template`, using `dest` as template instead
Injecting js files (14 files)
>> Nothing changed
Running "injector:css" (injector) task
Missing option `template`, using `dest` as template instead
Injecting css files (5 files)
>> Nothing changed
Running "wiredep:target" (wiredep) task
Running "autoprefixer:dist" (autoprefixer) task
Running "express:dev" (express) task
Starting background Express server
Debugger listening on port 5858
module.js:327
throw err;
^
Error: Cannot find module 'mongodb/node_modules/bson'
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\Rohit\Documents\GitHub\sangam\node_modules\mongoose\lib\drivers\node-mongodb-native\objectid.js:8:16)
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)
Running "wait" task
>> Waiting for server reload...
Done waiting!
Running "open:server" (open) task
Running "watch" task
Waiting...
after running grunt serve , I get that error
"cannot find module 'mongodb/node_modules/bson'" ,
the localhost page opens , but I get " cant reach this page" , please help me with this

As written in the github-issue try doing following steps:-
Make sure these two packages are at these versions
"mongodb": "^2.1.16",
"mongoose": "^4.4.12"
npm install -g node-gyp
cd /to/your/project-folder
rm -rf node_modules
npm install
Also try doing :-
do npm install inside node_modules/mongodb.
Hope this will help you.

Try changing mongoose 4.2.8 into to package.json and npm install again.
It worked for me locally as well as on heroku.

what i did
Just deleted node_modules folder and run
npm install
it worked fine.

definitely it's important to do a:
npm install -g node-gyp
cd /to/your/project-folder
rm -rf node_modules
npm install

Related

Node Modules Not Found, Using Ubuntu 20.04.5

I an a Windows 10 user who uses WSL. I was using Ubuntu 20.04.5 provided from the Microsoft Store and executing node commands with no issues. However, I attempted to update Ubuntu 20.04.5 to Ubuntu Jammy (22.x) and I found that it was generating some errors when I attempted to utilize nodejs after installing nodejs and npm.
I decided to go back to using Ubuntu 20.04.5, and after reinstalling nodejs and npm I am encountering the same issues I had on Jammy. When I try to run my plain JavaScript app using node, I am greeted with the following error.
So far, I have found nothing that has solved my problem.
I also tried restarting the terminal as well as my computer. I am continually met with an error indicating that it cannot find the modules I am looking for. Please note that I have not used yarn or curl for any downloads, and have only used apt install as well as npm install.
When I attempt to run my app.js file in the correct directory.
>> node app.js
noseinternal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'stream/promises'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/mnt/c/Users/.../group-project-1-group-6-15064/lib/weatherHandler.js:4:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
So far, the error seems to make sense. Even though I have a node_modules folder in the directory, it may not have the specific module it is trying to load.
So I then try to use the node install command to install all dependencies based on my package.json.
>> node install
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/mnt/c/Users/.../group-project-1-group-6-15064/install'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
This command worked perfectly before I reinstalled everything.
I also tried to add to the PATH in my .bashrc file to no avail. I'm sure it's something so simple and frustrating, but after over 30 hours of troubleshooting, I have yet to have any kind of breakthrough.
Possibly useful info:
>> which node
/usr/bin/node
>> node -v
V10.19.0
>> which npm
/usr/bin/npm
>> npm -v
6.14.4
>> sudo npm install --global --verbose nodejs
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/bin/npm',
npm verb cli 'install',
npm verb cli '--global',
npm verb cli '--verbose',
npm verb cli 'nodejs' ]
npm info using npm#6.14.4
npm info using node#v10.19.0
...
npm verb unbuild rmStuff nodejs#0.0.0 from /usr/local/lib/node_modules
...
npm verb exit [ 0, true ]
stream/promises was added in Node 15: https://nodejs.org/api/stream.html#streams-promises-api.
You have to update your Node.js, for that please refer to: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
You may use nvm to install and manage Node versions
# Download curl CLI utility
sudo apt-get install curl
# download nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
command -v nvm
If that doesn't work refer to nvm's troubleshooting guide.
Once you setup nvm, you can run
nvm install 16 # For example to install Node.js v16
nvm use 16 # To enable it in your current terminal
After that, you may need to reinstall your packages to avoid any unwanted behavior, just delete node_modules in your current project and re-run npm install.

Issue running grunt command Error: Cannot find module 'has'

I am facing errors with grunt commands for a dojo project with following version of node, npm and grunt-cli
grunt-cli version : 0.1.13
node version : 6.17.1
npm version : 3.10.10
Getting below error when running grunt command after npm install.
PS C:\workspace\ui\test\ui> grunt
module.js:478
throw err;
^
Error: Cannot find module 'has'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\6110853\AppData\Roaming\nvm\v6.17.1\node_modules\grunt-cli\node_modules\is-core-module\index.js:3:11)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
Tried npm install after deleting node_modules.
Tried installing has module before running npm-install
grunt-cli has been installed globally and I see the required module is present in node_module but we still get module not found error.
Can anybody suggest how to resolve this issue ?
This may be caused by incompatible dependencies. I encountered the same error on grunt#1.3.0. Upgrading node/npm tools to newer versions solved the problem in my case:
node#6.3.1 -> node#12.14.0
npm#3.10.3 -> npm#6.13.4

Cant see npm version on ubuntu because of Error: Cannot find module 'semver'

I reinstalled ubuntu on my machine and after that installed node, react, npm, when i tried to start old project and run into same error when i started the project but also when i tried to see version of npm.
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module 'semver'
Require stack:
- /usr/share/npm/lib/utils/unsupported.js
- /usr/share/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/npm/lib/utils/unsupported.js',
'/usr/share/npm/bin/npm-cli.js'
]
}
I uninstalled and installed npm again but it didnt help
Try this link anotehr SO post
Basically what they are doing is the below steps:
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf ~/.npm
brew uninstall --force node
brew install node
replace brew with respective package manager
You generally don't need to install npm separately. npm is bundled with node and the version that is bundled will generally work with the version of node you are running. If you install npm separately, you run the risk of installing an incompatible version of node.
So uninstall npm. See if you still have an npm available. If not, uninstall and reinstall node. Do not install npm separately (unless it is using npm itself to update to a newer version of npm with npm install -g npm.)

How to fix docker container running 'cannot find module' error?

I am new to docker and trying to move my MERRN stack application to AWS. I want to dockerize it before I move it. However, when I followed this online tutorial at Medium - Docker with MERN stack I get to the part with starting up my docker image with docker run -p 5000:5000 -d backend and I get an error in VS code. I am not sure what this error means but I theorize it has to do with my folder management.
I will attach a snippet of my folder structure as well as the docker file I used. So my main problem is I am trying to get everything setup but this issue is hindering my progress. So any help would be appreciated. Thanks
DockerFile:
FROM node:10.19.0
# Create app directory
WORKDIR /usr/src/app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# Bundle app source
COPY . .
# Install app dependencies
RUN npm install
EXPOSE 5000
CMD [ "npm", "start" ]
Error:
> exodus#1.0.0 start /usr/src/app
> node server
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './routes/api/Email'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/src/app/server.js:24:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! exodus#1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the exodus#1.0.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! /root/.npm/_logs/2020-10-28T20_13_53_160Z-debug.log
Search...
Stick to bottom
Your Dockerfile seems ok and your project structure, too.
I assume that the docker image is faulty for some reason and missing the files.
Can you try to build the image again? Is the COPY step executed correctly?
// Make sure to execute this in the project root.
docker build -t backend .
If the error persists, log into the docker container using bash or sh and try to manually start the node server with npm start:
docker run -p 5000:5000 -d backend /bin/bash
or
docker run -p 5000:5000 -d backend /bin/sh
Logging into the docker container will also help to investigate if e.g. some files were not transferred.

GithubElectron: A JavaScript error occured in the browser process

I installed "electron-packager" using npm and executed the command
electron-packager . Johnston --platform=darwin --arch=x64 --version=0.36.0
And then I when I run the "Johnston.app", this error showed up (I didn't even see the main window)
Uncaught Exception: Error: Cannot find module 'electron'
at Function.Module._resolveFilename (module.js:332:15)
at Function.Module._load (module.js:282:25)
at Module.require (module.js:361:17)
at require (module.js:380:17)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/app/main.js:3:18)
at Module._compile (module.js:426:26)
at Object.Module._extensions..js (module.js:444:10)
at Module.load (module.js:351:32)
at Function.Module._load (module.js:306:12)
at Object. (/Users/David/Github/Johnston/Johnston-darwin-x64/Johnston.app/Contents/Resources/atom.asar/browser/lib/init.js:104:10)
Is there any solutions? Thanks!
This likely has something to do with you having a different version of Electron installed on your machine that you are using to build with. In the folder for your app, run electron --version to get the version of electron that you have installed. Then, change the --version=0.36.0 to use whatever version you have installed.
If that doesn't fix it, then you should try rm -rf node_modules && npm install on your project. This will remove you node modules and then reinstall them all. If that doesn't work, please comment here and I will try to help again.

Categories