internal/modules/cjs/loader.js:883 throw err; - javascript

Here is the code:
const fs= require("fs");
const text=fs.readFileSync("dele.txt","utf-8");
console.log(text);
Here is the error in terminal:
Error: Cannot find module 'D:\programs\web development\tut64.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

In your script you are asking for fs module.
Try to run npm install fs in your console and be sure that you are running the command in your root folder.

Related

npx create-react-app is not working (node:internal/modules/cjs/loader:1042)

I tried to create a react application with typing "npx create-react-app myapp" but I got the following error:
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.13.0
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.13.0
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.13.0
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.13.0
Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts#0.9.x has failed.
Deleting generated file... package.json
Deleting ousseini_portfolio/ from C:\Users\USER\Desktop
Done.

I'm trying to run my node project on my vs code terminal

node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\desktop\dev-folder\node\node.js'
←[90m at Module._resolveFilename (node:internal/modules/cjs/loader:985:15)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:833:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
Node.js v18.10.0
PS C:\Users\user\desktop\dev-folder\node> node node -v
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\desktop\dev-folder\node\node'
←[90m at Module._resolveFilename (node:internal/modules/cjs/loader:985:15)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:833:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
Then i get this error,But if i run it on my CLi it works perfectly
i tried running it on my CLi it worked perfectly but when i run it on
vs code integrated terminal it doesn't work
is exactly path C:\Users\user\desktop\dev-folder\node\node?
You can get path of file in vscode:
Right click in file js need to run
Click Copy Path
In vscode terminal, run node {path_copied}
Try the below command:
go to the folder path in vs terminal
run node <filename.js>

at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\kpkbo\Desktop\web development for internship\chat-app\server\index.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint
[as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...
Yesterday it was running properly but today when i started its not working i tried installing all node modules again but still not working

NODE [ERR_MODULE_NOT_FOUND]: Cannot find module './config/app'

FIXED, the names of the folders in my pc changed when uploaded to github
So, my app looks something like this
├── config
| ├── app.js
|
└── index.js
app.js
Here i have all my env variables, so I have a central point from which to extract them
require('dotenv').config()
module.exports = {
appPort: process.env.PORT,
appUrl: process.env.APP_URL,
appKey: process.env.APP_KEY,
frontendUrl: process.env.FRONTEND_URL
}
index.js
central file of the server
const express = require('express')
const cors = require('cors')
const app = express()
const { appPort, frontendUrl } = require('./config/app')
app.listen(appPort , () => {
console.log(`Server listening on port ${appPort}`);
})
The problem here is that when i deploy it and starts the server, it throws me error
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './config/app'
Require stack:
- /app/index.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:102:18)
at Object.<anonymous> (/app/index.js:8:34)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/index.js' ]
}
and i really don't know why, because it works perfectly fine in my pc
the code for the whole project is actually much bigger, but only this files are the ones throwing me errors
Hope someone can help see what is happening that throws that error

cannot find module in node express

cannot find module in node express
Actual code
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
error code in cmd
C:\Users\user\Desktop\project>npm express -v
7.5.3
C:\Users\user\Desktop\project>npm utils -v
7.5.3
C:\Users\user\Desktop\project>node server
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module './utils'
Require stack:
- C:\Users\user\Desktop\project\node_modules\qs\lib\stringify.js
- C:\Users\user\Desktop\project\node_modules\qs\lib\index.js
- C:\Users\user\Desktop\project\node_modules\express\lib\middleware\query.js
- C:\Users\user\Desktop\project\node_modules\express\lib\application.js
- C:\Users\user\Desktop\project\node_modules\express\lib\express.js
- C:\Users\user\Desktop\project\node_modules\express\index.js
- C:\Users\user\Desktop\project\server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\user\Desktop\project\node_modules\qs\lib\stringify.js:3:13)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\user\\Desktop\\project\\node_modules\\qs\\lib\\stringify.js',
'C:\\Users\\user\\Desktop\\project\\node_modules\\qs\\lib\\index.js',
'C:\\Users\\user\\Desktop\\project\\node_modules\\express\\lib\\middleware\\query.js',
'C:\\Users\\user\\Desktop\\project\\node_modules\\express\\lib\\application.js',
'C:\\Users\\user\\Desktop\\project\\node_modules\\express\\lib\\express.js',
'C:\\Users\\user\\Desktop\\project\\node_modules\\express\\index.js',
'C:\\Users\\user\\Desktop\\project\\server.js'
]
}
first try to remove the globally installed express
then initialize a package.json file with npm init. Here you will have a list of your dependencies, scripts and name of your package and some other data.
Then install express with npm i express.
after installing try to run it with node server.js or npm start if you have written the script to run the start command in package.json
I got the answer
Download utils https://www.npmjs.com/package/utils
this is the error
C:\Users\user\Desktop\project>
node server
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module 'utils'
Require stack:
- C:\Users\user\Desktop\project\server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\user\Desktop\project\server.js:3:15)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'C:\\Users\\user\\Desktop\\project\\server.js' ]
}
C:\Users\user\Desktop\project>
npm i utils
added 43 packages, removed 2 packages, changed 3 packages, and audited 110 packages in 16s
found 0 vulnerabilities
C:\Users\user\Desktop\project>node server
Example app listening at http://localhost:3000
^C
C:\Users\user\Desktop\project>

Categories