Cannot find module (Error: Cannot find module './models/campground') - javascript

this is my code
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
Campground = require("./models/campground"),
Comment = require("./models/comment"),
seedDB = require("./seeds")
this are my file's tree
and when i run the above code, i get this error,
Error: Cannot find module './models/campground'
Require stack:
- /workspace/webDevBootcamp/yelpcamp/v4/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/workspace/webDevBootcamp/yelpcamp/v4/app.js:5:19)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/workspace/webDevBootcamp/yelpcamp/v4/app.js' ]
}

Replace
Campground = require("./models/campground"),
By
Campground = require("./models/campgorund"),
Or change the filename "campgorund.js" to "campground.js".
:)

Related

fix Error: Cannot find module 'crypto-js/sha256'

When I run the code, I get this error:
node:internal/modules/cjs/loader:949
throw err;
^
Error: Cannot find module 'crypto-js/sha256'
Require stack:
- /Users/admin/Desktop/Full-stack development/blockchain/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
at Module._load (node:internal/modules/cjs/loader:787:27)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/admin/Desktop/Full-stack development/blockchain/index.js:1:14)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/admin/Desktop/Full-stack development/blockchain/index.js' ]
}
Node.js v18.4.0
and here is my code:
const hash = require('crypto-js/sha256');
class Block {
constructor(prevHash, data) {
this.prevHash = prevHash;
this.data = data;
this.timeStamp = new Date();
this.hash = this.calculateHash();
}
calculateHash() {
return hash(this.prevHash + JSON.stringify(this.data) + this.timeStamp).toString();
}
}
const block = new Block('', {
hello: 'world'
});
console.log(block);
I ran the command: node index.js.
And I have fully installed nodejs, npm.
Here is the version I'm using:
admin#Admins-iMac ~ % node --version
v18.4.0
admin#Admins-iMac ~ % npm --version
8.12.1
I don't know why my program is crashing, please help me

NodeJS gui module not found

I attempting to use node.js with nodegui module but i got this error
node:internal/modules/cjs/loader:1189
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: The specified module could not be found.
\\?\C:\Users\Kacper\Desktop\sot\node_modules\#nodegui\nodegui\build\Release\nodegui_core.node
←[90m at Object.Module._extensions..node (node:internal/modules/cjs/loader:1189:18)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:102:18)←[39m
at Object.<anonymous> (C:\Users\Kacper\Desktop\sot\node_modules\←[4m#nodegui←[24m\nodegui\dist\lib\utils\addon.js:3:15)
←[90m at Module._compile (node:internal/modules/cjs/loader:1105:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m {
code: ←[32m'ERR_DLOPEN_FAILED'←[39m
index.js code
const { QLabel, QMainWindow } = require("#nodegui/nodegui");
const win = new QMainWindow();
const label = new QLabel(win);
label.setText("Hello world");
label.setInlineStyle("color: green; background-color: white;");
win.show();
global.win = win;
node v16.16.0
npm 8.11.0
windows 10 20h2

Getting MODULE_NOT_FOUND error when using require() for a .js file in sub directory

Using ExpressJS, when I run my project using 'node server.js' command, I get the following error:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '../config/db.config.js'
Require stack:
/Users/umairkhan/Documents/nodejs/bohra-calendar/db.js
/Users/umairkhan/Documents/nodejs/bohra-calendar/models/event.model.js
/Users/umairkhan/Documents/nodejs/bohra-calendar/controllers/event.controller.js
/Users/umairkhan/Documents/nodejs/bohra-calendar/routes/event.routes.js
/Users/umairkhan/Documents/nodejs/bohra-calendar/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:94:18)
at Object. (/Users/umairkhan/Documents/nodejs/bohra-calendar/db.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/umairkhan/Documents/nodejs/bohra-calendar/db.js',
'/Users/umairkhan/Documents/nodejs/bohra-calendar/models/event.model.js',
'/Users/umairkhan/Documents/nodejs/bohra-calendar/controllers/event.controller.js',
'/Users/umairkhan/Documents/nodejs/bohra-calendar/routes/event.routes.js',
'/Users/umairkhan/Documents/nodejs/bohra-calendar/server.js'
]
}
This is my code inside the db.js file:
const mysql = require("mysql");
var dbConfig = require("../config/db.config.js");
// Create a connection to the database
const connection = mysql.createConnection({
host: dbConfig.HOST,
user: dbConfig.USER,
password: dbConfig.PASSWORD,
database: dbConfig.DB
});
// open the MySQL connection
connection.connect(error => {
if (error) throw error;
console.log("Successfully connected to the database.");
});
module.exports = connection;
Here is the directory structure of the project.
I have also tried this path: './config/db.config.js' but I still get the same error.
Can someone please help?

Error: Cannot find module in node js

I want to add logInPageTest.js in a file with the require field, but when I am adding it , it is throwing this error.
module.js:472
throw err;
^
Error: Cannot find module './test-cases/logInPageTest.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/app/PycharmProjects/AutomationAppTesting/automationTest/index.js:15:15)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
Hierarchy is as follows:
-AutomationAppTesting
--automaitonTest
---test-cases
----logInPageTest.js
---index.js
Here is my code in index.js file:
require('./test-cases/logInPageTest.js')
Code in logInPageTest.js file:
var wd = require('wd');
var assert = require('assert');
module.exports = function (browser, next) {
maximizeWindow(browser, next);
}
function maximizeWindow(browser, next) {
browser .windowHandle( function (err, handle) {
browser.maximize(handle);
})
}
So, How should I give path to solve the error.

Node js , Error: can not find module

Here is the error which I get when I run nodejs app.js
module.js:340
throw err;
^
Error: Cannot find module 'share'
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> (/home/quicksilver/project/master/app.js:3:17)
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)
I am repeatedly getting this error :
I have already done npm install -g share several times ,but it has been no use.
var express = require('express')
var sharejs = require('share')
var connect = require('connect')
var AWS = require('aws-sdk');
//var zmq = require('zmq');
var app = express();
app.set('view options', {layout: false});
var problem={};
var sharejs_server;
AWS.config.loadFromPath('./awsconfig.json');
locomotive.boot('.', app.settings.env, function(err, app) {
var options = {};
if (err) { throw err; }
options.db = app.locals.db;
sharejs_server = sharejs.server.attach(app, options);
app.listen(app.locals.port, app.locals.ip, function () {
var addr = this.address();
console.log('listening on %s:%d', addr.address, addr.port);
});
});

Categories

Resources