Cannot find Module when running Node.js - node.js

This is my first time running node.js, and I have file located in C:\source, called index.js. I am not sure what am doing wrong here. I checked if node was installed with node -v and the version number appeared so that seems fine. Any input?
C:\source>node index.js
internal/modules/cjs/loader.js:783
throw err;
^
Error: Cannot find module 'C:\source\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
at Function.Module._load (internal/modules/cjs/loader.js:685:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
index.js has:
console.log('Hello World')

Related

No definite solution on Windows for Cannot find module 'graceful-fs' Error on React Native App Create Start Up

`PS C:\Users\Adrien\Documents\ReactNativeProjects> npx react-native start
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'graceful-fs'
Require stack:
- C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js
- C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\bin.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at _gracefulFs (C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js:15:39)
at Object.<anonymous> (C:\Users\Adrien\AppData\Local\npm-cache\_npx\7930a8670f922cdb\node_modules\#react-native-community\cli\build\tools\gracefulifyFs.js:22:1) at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Adrien\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\tools\\gracefulifyFs.js',
'C:\\Users\\Adrien\\AppData\\Local\\npm-cache\\_npx\\7930a8670f922cdb\\node_modules\\#react-native-community\\cli\\build\\bin.js'
]
}
Node.js v18.13.0
Everytime I tried to create an App I got this as a response.
I tried to Open a Project like,
npx react-native init App2
I was expecting was for the project to get built, appear so that I could see all the project files.
I tried uninstalling and then reinstalling like,
npm install 'graceful-fs'
I tried the other solutions here too like apt-get or sudo and curl but it didn't work in my terminal`

pod install fails in integrated vs terminal

I'm trying to run a pod update from my integrated VS-code terminal (react-native project) but it keeps throwing this error:
node:internal/modules/cjs/loader:936 throw err; ^
Error: Cannot find module '/Users/.../App/node_modules/#react-native-community/cli/build/bin.js Debugger attached. Waiting for the debugger to disconnect...'
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: [] }
Node.js v17.6.0
[!] Invalid `Podfile` file: 859: unexpected token at ''.
target 'appname' do
config = use_native_modules! use_react_native!(
I already tried removing package-lock.json, node_modules, and reinstalling.
If I run the command in a normal terminal I have no problems, any ideas?
Please try this:
step 1: pod deintegrate
step 2: pod install

Node 18.04.0 - Cannot find module node:test

I am trying to use node:test runner library and need to update a nonstable version of node.js 18.04 +
And this is the error that I have got
node:internal/modules/cjs/loader:949
throw err;
^
Error: Cannot find module '/home/project_name/out/test'
at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
at Module._load (node:internal/modules/cjs/loader:787: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: []
}
Update to the latest #types/node if you are using typescript.
yarn add -D #types/node
If you are using JS in node#18, it should automatically work
const test = require('node:test');

node.js cannot find module "mongodb"

I'm trying to connect my node js file to mongodb but I keep running into this error. mongodb is in the node_modules file. I'm unsure of what Im doing wrong
node mongstuff.js
internal/modules/cjs/loader.js:670
throw err;
^
Error: Cannot find module '/home/mohammed/node_modules/mongstuff.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
at Function.Module._load (internal/modules/cjs/loader.js:591:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11

Can't run node.js server locally

I'd like to run node.js server on my machine but I get this error. What should I do? (Please note I'm not programmer :)
MBP-Mike:~ michal$ node server
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/Users/michal/server'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
to run a nodejs server:
node
example: if your server file is called server.js
node /Users/Michal/server.js
it seems like you missed the .js extension on your command.
node server.js
Or you can just run
node .

Resources