Cannot find module error when running JS in terminal - javascript

It's my firt time using node today and I was faced with this issue. When trying to run hello.js in my terminal, I get this error :
Error: Cannot find module '/Users/antoinelafonta/hello.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: []
It's running fine when using the VsCode terminal.
Any ideas ?
Thanks !

Related

How do I solve this error message? I'm missing server.generated.js

Whenever I try to run my app with npm start in the terminal, this is the error I get:
iteh-projekat#1.0.0 start
> NODE_ENV=production node ./dist/server.generated.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/Users/mihailomitrovic/Downloads/iteh_projekat/dist/server.generated.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: []
}
Could someone help me with fixing this? The dist folder is empty, so I'm not sure what's happening. I've done npm install when pulling it from Github, since I'm working on it with friends for a uni project. Thank you!

Cannot find module 'discord.js', console reporting

I am very new using discord's javascript
This is also my first time posting on stackoverflow!
Anyway
Here's the full error
Error: Cannot find module 'discord.js'
Require stack:
- /home/runner/multiple-purpose-discord-bot-like-carlbot/xp.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> (/home/runner/multiple-purpose-discord-bot-like-carlbot/xp.js:1:17)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159: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: [ '/home/runner/multiple-purpose-discord-bot-like-carlbot/xp.js' ]
}
To my limited knowledge, this is either i made a typo
OR some package is outdated, here's the full packages list
I also suspect that i incorrectly implemented the amethyste-api i am using, here's my code
It's in a config file, should've i put const mySecret = process.env['ame'] in the main file instead?, I do need it to be in the config for ease of access
npm install discord.js (manually through console/shell)
did do some stuff but stil didn't work
npm xp.js (manually through console/shell)
this is what i am supposed to run on start manually, that what gives the error
You could run the following commands one after the other:
`npm init`
and then
`npm i discord.js`

Cannot find module '/workspace/index.js' error after repository push attempt to railway.app

I just had an error I just fixed, but now I am getting this error saying cannot find module workspace, I have no idea what workspace is.
Here is the full error:
Error: Cannot find module '/workspace/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: []
}
I don't know how to fix this issue so I would really appreciate it if someone helped me with this one. If you can't help but had the time to view it, still thank you!
1.Do you have Node.js installed on your machine?
2.If you have installed node.js, use <node (name of your main file).js> to run
3.Check for the following in the JSON file:
"scripts": {
"start": "node index.js"
},

Facing issue to run JavaScript file

I am facing issue to run the JavaScript file in VS code.
I am getting the output as:-
[Running] node "e:\n\Temporay folders of web development\vs code project\tut64.js"
node:internal/fs/utils:343
throw err;
^
Error: ENOENT: no such file or directory, open 'tut64.txt'
at Object.openSync (node:fs:582:3)
at Object.readFileSync (node:fs:450:35)
at Object.<anonymous> (e:\n\Temporay folders of web development\vs code project\tut64.js:2:17)
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 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'tut64.txt'
}
[Done] exited with code=1 in 0.839 seconds
And in the terminal I am getting:-
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS E:\n\Temporay folders of web development\vs code project> node \tut64.js\
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'E:\tut64.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:79:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I am not getting what type of these errors are and why I am getting them.
In the terminal you should do node tut64.js
And check the path of tut64.txt or post your code.

throw err/MODULE_NOT_FOUND

I am having this issue when trying to run node index.js in my terminal on VSC.
This is the error,
[Try the new cross-platform PowerShell https://aka.ms/pscore6
PS Z:\01 Code notes> node index.js
node:internal/modules/cjs/loader:944
throw err;
^
Error: Cannot find module 'Z:\01 Code notes\index.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
PS Z:\01 Code notes> ][1]
I have tried so many different things. I tried all the suggested fixes on these pages,
Node MODULE_NOT_FOUND
Why does VsCode NPM throw a module not found error?
https://github.com/Microsoft/vscode/issues/65893
Any suggestions?
That means you are using a module that you haven't installed, check your code.

Categories

Resources