Error: Cannot find module './Mime' - node.js

I am trying to get a heroku project running (following the tutorial here) and I'm running into a bit of trouble.
The node task on Heroku is throwing the following:
app[web.1]: module.js:540
app[web.1]: throw err;
app[web.1]: ^
app[web.1]:
app[web.1]: Error: Cannot find module './Mime'
app[web.1]: at Function.Module._resolveFilename (module.js:538:15)
app[web.1]: at Function.Module._load (module.js:468:25)
app[web.1]: at Module.require (module.js:587:17)
app[web.1]: at Object.<anonymous> (/app/node_modules/mime/index.js:3:12)
app[web.1]: at require (internal/module.js:11:18)
app[web.1]: at Module._compile (module.js:643:30)
app[web.1]: at Object.Module._extensions..js (module.js:654:10)
app[web.1]: at Module.load (module.js:556:32)
app[web.1]: at tryModuleLoad (module.js:499:12)
app[web.1]: at Function.Module._load (module.js:491:3)
I have installed (with -save) all of the dependencies I need including mime, but it seems like it's getting caught up with the mime module itself, here's the mime node_module:
1,545 .eslintrc.json
<DIR> .github
9,230 CHANGELOG.md
157 cli.js
127 index.js
1,098 LICENSE
101 lite.js
1,951 Mime.js
2,824 package.json
5,468 README.md
<DIR> src
<DIR> types
The mime/index.js file:
'use strict';
var Mime = require('./Mime');
module.exports = new Mime(require('./types/standard'), require('./types/other'));
and my project's dependencies
"dependencies": {
"body-parser": "^1.15.2",
"cheerio": "^1.0.0-rc.2",
"cookie-parser": "^1.4.3",
"express": "^4.14.0",
"express-handlebars": "^3.0.0",
"express-less": "^0.1.0",
"express-minify": "^0.2.0",
"favicon": "0.0.2",
"helmet": "^2.3.0",
"http": "0.0.0",
"logger": "0.0.1",
"mime": "^2.0.3",
"mongodb": "^2.2.11",
"morgan": "^1.7.0",
"nodemailer": "^4.4.1",
"nodemailer-sendgrid-transport": "^0.2.0",
"path": "^0.12.7",
"serve-favicon": "^2.3.0"
}
Thanks for your help!

Whelp, hard to say 100% what I did to fix the issue but it was probably one of the following things.
I added "engines": {"node": "7.5.0","npm": "4.1.2"} to my node package (see here)
I added a Procfile to the root with web: node server.js (see here)
as a side note, caching was a big issue for me after I solved this issue. This link may help with that.

Related

Error: Cannot find module 'node-events' | Discord.js

I am running a Discord bot using Discord.js on Repl.it, and just recently upgraded my Discord.js to the latest 13.6.0 version, and ever since have gotten this error my console as soon as I try to run my application.
Error: Cannot find module 'node-events' | Discord.js
Require stack:
- /home/runner/myBot/node_modules/discord.js/src/client/BaseClient.js
- /home/runner/myBot/node_modules/discord.js/src/index.js
- /home/runner/myBot/node_modules/discord.js-commando/src/client.js
- /home/runner/myBot/node_modules/discord.js-commando/src/index.js
- /home/runner/myBot/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/runner/myBot/node_modules/discord.js/src/client/BaseClient.js:3:22)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
Now, I have updated my Node.js version to 16.6.1, like was suggested by basically every post I could find about this error, but that still didn't quite seem to fix it. Running the node -v command in my Repl.it shell returns 16.6.1, as it should, and so I don't really know what I'm missing at this point.
I will put my package.json down below too, if it can help.
If anyone knows how I could fix this issue, I would gladly appreciate it.
Thank you in advance!
{
"name": "myBot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node ."
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#replit/database": "^2.0.1",
"base": "^3.0.0",
"canvas": "^2.9.0",
"common-tags": "^1.8.0",
"discord": "^0.8.2",
"discord.js": "^13.6.0",
"discord.js-commando": "^0.12.3",
"dotenv": "^10.0.0",
"events": "^3.3.0",
"express": "^4.17.1",
"init": "^0.1.2",
"node-events": "0.0.2",
"node-fetch": "^2.6.1",
"snekfetch": "^4.0.4",
"twitch": "^4.6.0"
},
"devDependencies": {
"node": "^16.6.1"
},
"description": ""
}

Gulp exited witch code 1 in VS2017 - Build failed

I have an error when I try to build mvc solution.
The command "gulp" exited with code 1
When I go to output window I can see this
1> ReferenceError: primordials is not defined
1> at fs.js:47:5
1> at req_ (C:\Work\tiptimes\MvcApplication\node_modules\natives\index.js:143:24)
1> at Object.req [as require] (C:\Work\tiptimes\MvcApplication\node_modules\natives\index.js:55:10)
1> at Object.<anonymous> (C:\Work\tiptimes\MvcApplication\node_modules\graceful-fs\fs.js:1:37)
1> at Module._compile (node:internal/modules/cjs/loader:1095:14)
1> at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
1> at Module.load (node:internal/modules/cjs/loader:975:32)
1> at Function.Module._load (node:internal/modules/cjs/loader:816:12)
1> at Module.require (node:internal/modules/cjs/loader:999:19)
1> at require (node:internal/modules/cjs/helpers:93:18)
I setup global variable to the NODE_PATH to reference npm/modules.
Here is my list of dependencies:
"engines": {
"node": "5.9.1",
"npm": "3.7.3"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.1.0",
"gulp-minify-css": "^1.2.4",
"gulp-sourcemaps": "^2.3.0",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.7",
"merge-stream": "^1.0.0"
}
}

Node Sass Error: Cannot find module 'mkdirp'

I have the following package.json
"devDependencies": {
"bootstrap-sass": "*",
"buble": "^0.12.5",
"css-loader": "^0.25.0",
"gulp": "*",
"jquery": "^3.1.0",
"json-loader": "^0.5.4",
"laravel-elixir": "^6.0.0-14",
"laravel-elixir-browsersync-official": "^1.0.0",
"laravel-elixir-vue-2": "^0.2.0",
"laravel-elixir-webpack-official": "^1.0.2",
"lodash": "^4.16.2",
"sass": "*",
"sass-loader": "*",
"vue": "^2.1.10",
"vue-loader": "^9.7.0",
"vue-resource": "^1.0.3",
"vue-router": "^2.0.0",
"vue-stash": "^2.0.1-beta",
"vue-template-compiler": "^2.1.10"
},
"dependencies": {
"bootstrap-datepicker": "^1.6.4",
"jquery-simple-upload": "^1.0.0",
"json-loader": "^0.5.4",
"moment": "*",
"natives": "^1.1.6",
"vuejs-datepicker": "^0.9.24"
}
On using Yarn to install the modules I am met with
warning "laravel-elixir-vue-2 > sass-loader#4.1.1" has unmet peer
dependency "webpack#^2 || ^2.2.0-rc.0 || ^2.1.0-beta || ^1.12.6".
[4/4] Building fresh packages... error
/home/vagrant/Code/xxx/node_modules/node-sass:
Command failed. Exit code: 1 Command: node scripts/install.js
Arguments: Directory:
/home/vagrant/Code/xxx/node_modules/node-sass
Output: internal/modules/cjs/loader.js:818 throw err; ^
Error: Cannot find module 'mkdirp' Require stack:
/home/vagrant/modules/xxx/node-sass/scripts/install.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/vagrant/modules/xxx/node-sass/scripts/install.js:7:11)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) { code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/vagrant/modules/xxx/node-sass/scripts/install.js' ]
I'm not sure why/ who is installing node-sass but it brings me to this point regardless if I yarn clean cache rm -rf package.lock.json or rm -rf node_modules
I'm using
yarn 1.22.10
node 12.20.0
npm 6.14.9
on Linux homestead 4.15.0-124-generic #127-Ubuntu
Looks like node LTS is 14.something.
Maybe try updating that (and everything else)?
Not sure where install "mkdirp".
but you can install mkdirp#lastest first,
then let yarn/npm install all package again
to see whether "mkdirp" is a really problem or not.
yarn add mkdirp#lastest // or npm i mkdirp#lastest
then
yarn install // or npm i

Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

I am trying to deploy my REST API to heroku. However, the application is not working. In the application log, i got this
Process exited with status 1
2019-09-23T01:09:55.744676+00:00 heroku[web.1]: Starting process with command `node server.js`
2019-09-23T01:09:58.446510+00:00 heroku[web.1]: Process exited with status 1
2019-09-23T01:09:58.468276+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-23T01:09:58.370869+00:00 app[web.1]: internal/modules/cjs/loader.js:807
2019-09-23T01:09:58.370888+00:00 app[web.1]: return process.dlopen(module, path.toNamespacedPath(filename));
2019-09-23T01:09:58.370890+00:00 app[web.1]: ^
2019-09-23T01:09:58.370892+00:00 app[web.1]:
2019-09-23T01:09:58.370894+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2019-09-23T01:09:58.370896+00:00 app[web.1]: at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
2019-09-23T01:09:58.370898+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370900+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370902+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370904+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370906+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370909+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2019-09-23T01:09:58.370910+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-09-23T01:09:58.370912+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-09-23T01:09:58.370915+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370917+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370919+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370921+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370923+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370924+00:00 app[web.1]: at Object.<anonymous> (/app/routes/auth.js:6:16)
2019-09-23T01:09:58.370926+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
This seems to have something to do with bcrypt module. I tried the solutions suggested here: https://github.com/kelektiv/node.bcrypt.js/issues/595 and https://github.com/kelektiv/node.bcrypt.js/issues/635
such as: npm rebuild bcrypt --build-from-source
here is package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.6",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"cron": "^1.7.2",
"express": "^4.16.3",
"jsonwebtoken": "^8.3.0",
"jwt-simple": "^0.5.6",
"mapnik": "^4.3.1",
"mkdirp": "^0.5.1",
"mongoose": "^5.7.1",
"multer": "^1.4.1",
"nodemailer": "^6.3.0",
"request": "^2.88.0",
"ug": "0.0.8"
}
}
None of those solutions worked for me! How can I solve this problem?
I had the same issue, but with Docker. Turns out the node_modules folder was being uploaded. Make sure to add node_modules to your .gitignore (and/or .dockerignore)
Make .gitignore file.
Run below commands in your terminal
git rm -r --cached node_modules
git commit -am "node_modules be gone!"
git push origin main
deploy to Heroku through GitHub or CLI

Node cannot find module ~/package.json (closed)

I'm trying to start my API with node but this error appears :
$ node ./.local/start.js
module.js:549
throw err;
^
Error: Cannot find module '/c/Users/$AAU000-TFETR2QTBK6P/Desktop/Stage/whasq-api-master/package.json'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at ConfigurationManager.getPackageConfig (C:\Users\$AAU000-TFETR2QTBK6P\Desktop\Stage\whasq-api-master\node_modules\#rduk\configuration\lib\manager.js:61:15)
at getDocument (C:\Users\$AAU000-TFETR2QTBK6P\Desktop\Stage\whasq-api-master\node_modules\#rduk\configuration\lib\manager.js:74:31)
at ConfigurationManager.getSection (C:\Users\$AAU000-TFETR2QTBK6P\Desktop\Stage\whasq-api-master\node_modules\#rduk\configuration\lib\manager.js:106:19)
at ConfigurationManager.get (C:\Users\$AAU000-TFETR2QTBK6P\Desktop\Stage\whasq-api-master\node_modules\#rduk\configuration\lib\manager.js:93:25)
at Object.<anonymous> (C:\Users\$AAU000-TFETR2QTBK6P\Desktop\Stage\whasq-api-master\index.js:14:38)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
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)
The real problem is that the file package.json is present..
ls -a (at ~/Desktop/Stage/whasq-api-master)
./ ../ .circleci/ .gitignore .local/ api/ config/ ecosystem.config.js index.js lib/ node_modules/ package.json package-lock.json README.md sf_certificate/ templatesES.md
//package.json content
{
"name": "whasq-api",
"version": "0.1.1",
"description": "whasq-api",
"engines": {
"node": ">=8.11.1"
},
"main": "index.js",
"scripts": {
"pretest": "standard --fix",
"test": "exit 0"
},
"author": "WhASQ",
"license": "ISC",
"dependencies": {
"#rduk/configuration": "^2.2.3",
"#rduk/errors": "^1.3.1",
"#rduk/logger": "^1.0.3",
"#rduk/logger-winston-loggly-factory": "0.1.0",
"#rduk/logger-winston-provider": "^1.0.4",
"#rduk/message-broker": "^2.4.0",
"#rduk/provider": "^3.1.3",
"#rduk/tasks-orchestrator": "^0.1.3",
"aws-sdk": "^2.256.1",
"axios": "^0.18.1",
"bcrypt": "^3.0.4",
"body-parser": "^1.18.2",
"csv": "^3.1.0",
"dotenv": "5.0.1",
"elasticsearch": "^16.4.0",
"express": "4.16.3",
"express-request-id": "^1.4.1",
"helmet": "^3.15.1",
"jsonwebtoken": "8.2.1",
"morgan": "^1.9.1",
"multer": "^1.3.1",
"orm": "^5.0.4",
"package.json": "^2.0.1",
"pg": "^7.4.1",
"react-s3-uploader": "^4.8.0",
"socket.io": "2.0.4",
"socketio-jwt": "4.5.0",
"standard": "11.0.1",
"swagger-express-mw": "0.7.0",
"winston": "2.4.0"
},
"directories": {
"lib": "lib"
},
"devDependencies": {},
"keywords": []
}
I tried a lot of things, like switch versions of Node, delete modules then reinstall them, and other stuff like that but I cannot solve this problem.
I'm using those versions :
npm 6.11.3 node 8.11.1 and I'm using GitBash (i tried Powershell but no change)
(I tried every single version of Node (>=8.11.1) and the error is the same every time)
ls -a (at ~/Desktop/Stage/whasq-api-master/.local)
.env start.js
//start.js content
require('dotenv').load({path: process.env.PWD + '/.local/.env'})
require('../')
//.env content
RDUK_CONFIG_PATH=config
RDUK_CONFIG_PREFIX=app
RDUK_CONFIG_EXT=.yaml
APP_PORT=6500
APP_SECRET=xxx
SF_SECRET=(hidden)
SF_CERTIFICATE=sf_certificate/public.pem
AMQP_ADDRESS=amqp://cawdev:cawdev#192.168.1.87:5672
LOGGLY_TOKEN=xxx
LOGGLY_SUBDOMAIN=xxx
LOGGLY_LOGIN=jessie
LOGGLY_PASSWORD=(hidden)
ES_ADDRESS=http://cawtest.net:9200/
DB_PROTOCOL=postgresql
DB_HOST=localhost
DB_PORT=5433
DB_NAME=mydb
DB_USER=esteban
DB_PASS=(hidden)
AWS_ACCESS_KEY_ID=(hidden)
AWS_SECRET_ACCESS_KEY=(hidden)
AWS_REGION=eu-west-3
AWS_BUCKET=(hidden)
I also tried to move my repository at C:/ to avoid potential problems with my username ($AAU000-TFETR2QTBK6P) because I thought that name could be mistaken for an environment variable.
The issue come from the way Windows interpret the npm library, I advise you to switch to a Linux or Mac environment..

Resources