OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Keep getting error# node:internal/modules/cjs/loader:1137 throw err; ^, whe running index.js file

  • Thread starter Thread starter Abhinav Banerjee
  • Start date Start date
A

Abhinav Banerjee

Guest
I am running command node index.js and getting below error:

Code:
node:internal/modules/cjs/loader:1137 throw err; ^

Error: Cannot find module '../models/User' Require stack:

/home/ubuntu/travel-community/server/routes/auth.js /home/ubuntu/travel-community/server/index.js at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15) at Module._load (node:internal/modules/cjs/loader:975:27) at Module.require (node:internal/modules/cjs/loader:1225:19) at require (node:internal/modules/helpers:177:18) at Object. (/home/ubuntu/travel-community/server/routes/auth.js:4:14) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Module.require (node:internal/modules/cjs/loader:1225:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/ubuntu/travel-community/server/routes/auth.js', '/home/ubuntu/travel-community/server/index.js' ] } Node.js v18.19.1

I have checked and files are in right place. Below is the configuration:

Code:
ubuntu@ip-172-31-21-235:~/travel-community/server$ ls

config index.js models node_modules package-lock.json package.json routes

Code:
ubuntu@ip-172-31-21-235:~/travel-community/server$ cd routes/
ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ ls

auth.js

Code:
ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ cd ..
ubuntu@ip-172-31-21-235:~/travel-community/server$ ls

config index.js models node_modules package-lock.json package.json routes

Code:
ubuntu@ip-172-31-21-235:~/travel-community/server$ cat index.js

Code:
const express = require('express'); 
const connectDB = require('./config/db'); 
const authRoutes = require('./routes/auth');

const app = express(); connectDB();

app.use(express.json());

app.use('/api/auth', authRoutes);

const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(Server running on port ${PORT}));

Can someone please help.

I am using AWS Ubuntu 24 (free tier).

<p>I am running command <code>node index.js</code> and getting below error:</p>
<pre><code>node:internal/modules/cjs/loader:1137 throw err; ^

Error: Cannot find module '../models/User' Require stack:

/home/ubuntu/travel-community/server/routes/auth.js /home/ubuntu/travel-community/server/index.js at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15) at Module._load (node:internal/modules/cjs/loader:975:27) at Module.require (node:internal/modules/cjs/loader:1225:19) at require (node:internal/modules/helpers:177:18) at Object. (/home/ubuntu/travel-community/server/routes/auth.js:4:14) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Module.require (node:internal/modules/cjs/loader:1225:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/ubuntu/travel-community/server/routes/auth.js', '/home/ubuntu/travel-community/server/index.js' ] } Node.js v18.19.1
</code></pre>
<p>I have checked and files are in right place. Below is the configuration:</p>
<pre><code>ubuntu@ip-172-31-21-235:~/travel-community/server$ ls
</code></pre>
<p>config index.js models node_modules package-lock.json package.json routes</p>
<pre><code>ubuntu@ip-172-31-21-235:~/travel-community/server$ cd routes/
ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ ls
</code></pre>
<p>auth.js</p>
<pre><code>ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ cd ..
ubuntu@ip-172-31-21-235:~/travel-community/server$ ls
</code></pre>
<p>config index.js models node_modules package-lock.json package.json routes</p>
<pre><code>ubuntu@ip-172-31-21-235:~/travel-community/server$ cat index.js
</code></pre>
<pre><code>const express = require('express');
const connectDB = require('./config/db');
const authRoutes = require('./routes/auth');

const app = express(); connectDB();

app.use(express.json());

app.use('/api/auth', authRoutes);

const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(Server running on port ${PORT}));
</code></pre>
<p>Can someone please help.</p>
<p>I am using AWS Ubuntu 24 (free tier).</p>
 
Top