Error: Cannot find module 'mongodb/node_modules/bson' - node.js

I am using node 8.1.2 with mongoose 4.11. On starting the app, I am getting these errors:
D:\express_learn\LAM>node app.js
module.js:487
throw err;
^
Error: Cannot find module 'mongodb/node_modules/bson'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\express_learn\LAM\node_modules\mongoose\lib\drivers\node-mongodb-native\objectid.js:8:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
D:\express_learn\LAM>
I tried the following solution from here
npm install node-gyp -g
npm cache clean
rm -rf node_modules
npm install
But still getting the same error.
Here is package.json
{
"name": "learn-about-me",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.6.5",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.3.2",
"ejs": "^1.0.0",
"express": "^4.15.3",
"express-session": "^1.7.6",
"mongoose": "^4.11.0",
"passport": "^0.2.0",
"passport-local": "^1.0.0"
}
}

Here is what I did to resolve the issue
npm cache clean --force
rm -f package-lock.json
node install

Related

npm error | Error: Cannot find module '#emotion/styled'

I am having an issue running my Node project. This issue did not exist yesterday. I can't think of anything that has changed since other than an update my OS did last night (Ubuntu 20.04).
Stack trace:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module '#emotion/styled'
Require stack:
- /home/jake/node_modules/#mui/styled-engine/node/index.js
- /home/jake/node_modules/#mui/system/index.js
- /home/jake/node_modules/#mui/core/node/Popper/Popper.js
- /home/jake/node_modules/#mui/core/node/Popper/index.js
- /home/jake/node_modules/#mui/core/node/index.js
- /home/jake/Documents/Dev/Stock-Informer/models/User.js
- /home/jake/Documents/Dev/Stock-Informer/middleware/passport-config.js
- /home/jake/Documents/Dev/Stock-Informer/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/jake/node_modules/#mui/styled-engine/node/index.js:45:38)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/jake/node_modules/#mui/styled-engine/node/index.js',
'/home/jake/node_modules/#mui/system/index.js',
'/home/jake/node_modules/#mui/core/node/Popper/Popper.js',
'/home/jake/node_modules/#mui/core/node/Popper/index.js',
'/home/jake/node_modules/#mui/core/node/index.js',
'/home/jake/Documents/Dev/Stock-Informer/models/User.js',
'/home/jake/Documents/Dev/Stock-Informer/middleware/passport-config.js',
'/home/jake/Documents/Dev/Stock-Informer/server.js'
]
}
[nodemon] app crashed - waiting for file changes before starting...
It's seems to want a React module, #emotion/style, but my project is not a React project.
package.json:
{
"name": "stock-informer",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-flash": "^0.0.2",
"express-session": "^1.17.2",
"mongoose": "^6.0.13",
"passport": "^0.5.0",
"passport-local": "^1.0.0",
"pug": "^3.0.2"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
I tried deleting node_modules and package-lock.json and running npm install, but it didn't change anything. I have also npm install #emotion/styled to see if that would do anything, but it didn't.
I haven't been able find a solution anywhere; any help would be appreciated.
I think I have faced a similar issue before the step that I follow
delete /node_modules
delete package-lock.json
run this command npm cache clean --force or yarn cache clean
npm install or yarn
Hope this will resolve your issue
The build process was excluding the indirect dependencies of my dependencies:
So adding the indirect dependencies as below worked:
import styled from "#emotion/styled";
let MustHave_DummyForSlsBuild = styled.div({
color: "hotpink",
});
<div className="App">
... main code here ...
<MustHave_DummyForSlsBuild></MustHave_DummyForSlsBuild>
</div>

Error: Cannot find module 'aws-api-gateway-client'

I am trying to execute nodejs code to invoke AWS API using aws-api-gateway-client module. Code workes perfectly in my laptop however when deployed to TEST server which has latest nodejs and aws npm module installed.
var apigClientFactory = require('aws-api-gateway-client')
Path Npm modules are installed:
C:\Program Files\nodejs\node_modules\npm\node_modules
Output
''' internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'aws-api-gateway-client'
Require stack:
- C:\Myfolder\agent\scripts\NodeJSAWSConnector\APINetworks.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> (C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js:8:25)
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: [
'C:\\MyFolder\\agent\\scripts\\NodeJSAWSConnector\\APINetworks.js'
]
}
'''
Please advise on the above issue.
Update 2:
package.json file has entry
"dependencies": {
"JSONStream": "^1.3.5",
"abbrev": "~1.1.1",
"ansicolors": "~0.3.2",
"ansistyles": "~0.1.3",
"aproba": "^2.0.0",
"archy": "~1.0.0",
"aws-api-gateway-client": "^0.3.3",
"aws-sdk": "^2.656.0",
"bin-links": "^1.1.7",
"bluebird": "^3.5.5",
"byte-size": "^5.0.1",
"cacache": "^12.0.3",
"call-limit": "^1.1.1",
"chownr": "^1.1.4",
"ci-info": "^2.0.0",
"cli-columns": "^3.1.2",
"cli-table3": "^0.5.1",
Also, aws-api-gateway-client is installed at C:\Program Files\nodejs\node_modules\npm\node_modules
Your app is in C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js
node_modules are in: C:\Program Files\nodejs\node_modules\npm\node_modules
Seems like You've installed aws-api-gateway-client globally (since You're saying that node_modules folder is in different place)
Steps to check and solve:
1) check package.json file if it exists in dependencies,
2) make sure in Your test server aws-api-gateway-client exists in node_modules folder,
3) do npm i --save aws-api-gateway-client to install it in node_modules folder relative to Your project, which will also add that module to dependencies in package.json
4) deploy to test server again with updated packge.json

When i execute $firebase deploy command i get this error?

I want to create an http function to upload image to firebase storage using firebase cloud functions.
package.json
"dependencies": {
"#google-cloud/storage": "^2.3.0",
"busboy": "^0.2.14",
"cors": "^2.8.5",
"firebase-admin": "^6.1.0",
"firebase-functions": "^2.1.0",
"uuid": "^3.3.2"
}
Error
Error: Error occurred while parsing your function triggers.
TypeError: require(...) is not a function
at Object.<anonymous> (/home/a7me63azza8/Desktop/flutter/flutter_course/functions/index.js:21:45)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /usr/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
at Object.<anonymous> (/usr/lib/node_modules/firebase-
tools/lib/triggerParser.js:53:3)
Error screen shot
I am doing the udemy flutter course as well, and there was a document that asked you to install version 1.7 of #google-cloud/storage.
This worked for me, run:
npm install --save #google-cloud/storage#1.7
then run: firebase deploy

node keystone Cannot find module './browserify'

Everything was working until I did a npm install on my project folder.
I am running macOS Sierra 10.12.5, node.js v8.2.1, npm v5.3.0
What I have tried:
uninstalling node/npm and reinstalling
npm install -g browserify
npm insatll browserify on my project folder
reinstall KeystoneJS generator
my package.json
{
"name": "site-name",
"version": "0.0.0",
"private": true,
"dependencies": {
"keystone": "4.0.0-beta.5",
"lodash": "^4.13.1",
"consolidate": "0.14.5",
"nunjucks": "3.0.0",
"node-sass": "4.5.0",
"node-sass-middleware": "0.11.0",
"dotenv": "4.0.0",
"async": "2.1.4",
"express-sslify": "1.2.0"
},
"devDependencies": {
"eslint": "3.15.0",
"eslint-config-keystone": "3.0.0",
"eslint-plugin-react": "^5.1.1"
},
"scripts": {
"lint": "eslint .",
"start": "node keystone.js"
}
}
Here is the output in terminal
node keystone
module.js:487
throw err;
^
Error: Cannot find module './browserify'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/Tyler/Desktop/Forge_Fitness_Site/models/node_modules/sha.js/bin.js:3:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:42:23
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:36:22
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:36:22
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at Keystone.import (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/index.js:176:42)
at Object.<anonymous> (/Users/Tyler/Desktop/Forge_Fitness_Site/keystone.js:41:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
Well, I fixed the issue, not exactly sure how it happened but somehow I ended up with two node_modules folders in my project directory. Deleting the second one fixed my issue.

Error: Cannot find module 'once'

Error: Cannot find module 'once'
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> (/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/got/node_modules/duplexify/node_modules/end-of-stream/index.js:1:74)
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)
I'm getting this error when I try running my server.js with nodemon. I looked in my node_modules folder and there is a 'once' folder in there. I tried
rm -rf node_modules
npm install
to remove the entire node_modules folder and reinstall but it didn't work. I also did
npm install --save once
and still didn't work.
This is package.json
{
"name": "FullMean_Friends",
"version": "0.0.1",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "latest",
"express": "~4.2.0",
"mongoose": "latest"
}
}

Resources