New to node.js found a possible PATH variable error - node.js

Fairly new to node.js and suddenly this error happened, I tried researching it and found out it could be PATH, but I tried adding it and could not find the solution.
C:\Windows\system32>node app.js --harmony
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'C:\Windows\system32\app.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I have no idea why your current working directory is C:\Windows\system32 but you really shouldn't be in there running Node code. That's for Windows specific system files only.
You'll need to change to the directory with app.js in it, or you'll need to specify the full path when running Node:
node C:\path\to\app.js --harmony
Like all command-line tools, the node program will look in the current directory unless told otherwise.

Related

How to run Jest tests on WebStorm and WSL

I'm trying run Run/Debug configuration on WebStorm. I have configuration:
And when I run that configuration I got:
module.js:540
throw err;
^
Error: Cannot find module '/home/dtokarczyk/Develop/Company/e-home-react/\wsl$UbuntuhomedtokarczykDevelopCompanye-home-reactnode_modulesjestbinjest.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Process finished with exit code 1
I don't know how jest path I should add. Terminal tests work fine.
using WSL2 UNC paths is not supported. Some related tickets (https://youtrack.jetbrains.com/issue/WEB-43279, for example) are fixed in the next major update (2020.1), but general support is still not there. Please follow IDEA-197573 and WEB-39819 for updates

Why does VsCode NPM throw a module not found error?

Typically I have no issues at all but however the other day VsCode started throwing a error anytime I tried to use a nodejs command. For instance even NPM -V throws a error. I have attempted to delete the environmental variables and reapply them as well as restart and I even completely wiped nodejs from my system both under program files and appData and re installed it. If I goto a normal cmd windows prompt I get zero issues. However if I am inside of vscode I get the below error:
npm -v
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'E:\c\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'E:\c\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
This is just a simple version command in VScode. Thanks in advance for the help!
I was able to resolve this by pressing F1 in VsCode and selecting the cmd as the default terminal option. The guys at vscode actually helped me! https://github.com/Microsoft/vscode/issues/65893
Thanks! Hopefully this helps someone in the future :)
If selecting the simple CMD as the default terminal in VsCode does not fix this problem for some, try running VsCode as an administrator.

npm-cli.js not found on git-bash

I have recently installed nodejs and npm on windows. Everything is fine with it. However, for some reason npm does work in cmd, but gives the following error when called on git-bash.
module.js:327
throw err;
^
Error: Cannot find module 'B:\b\programma's\Nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
module.js:327
throw err;
^
Error: Cannot find module 'B:\b\programma's\Nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
I noticed that the path apears to be B:\b\, meaning that somewhere npm selects the drive twice.
I am aware of the fact that my question looks a lot like this question. I did check my windows PATH variable, and the nodejs folder(including npm folder) are in there.
I also saw this post, and the git-bash does not tell me that npm is not found
I hope someone can help me with this problem
Looks like one of your directories has a ' in it. I would back everything up, change that directory to something simple like prog without any punctuation, uninstall Node and git-bash, and very carefully follow the instructions reinstalling them.

Node.js appends command to current working directory and throws an error

I just installed Node.js on my Windows 7 machine, added it to the PATH and tried to use it. npm works perfectly (at least for now) and node --version prints v4.1.2.
However, when I try to execute another command like node update it appends the command to the current working directory and, of course, fails :
$ node help
module.js:338
throw err;
^
Error: Cannot find module 'c:\path\to\working\directory\help'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:118:18)
at node.js:952:3
What can I do?

Sudo node server return error, OsX

There is the case:
mac:~ username$: sudo node server
module.js:340
throw err;
^
Error: Cannot find module '/Users/username/server'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
So here is 2 questions:
How to specify modules folder in node.js(node on my machine is taking place on /usr/local/bin/node); may be u could give me a advice how I may organise my project files.
How could I prevent this type of errors in future? What could I read about it?
I think you don't get what exactly Node will do with your command.
With this command, Node is trying to load a script file (in your current folder) with no extension named server.
It looks like this file doesn't exist in your current directory.
Let's take a simple example: you have a file named app.js in your current folder which contains a simple output in the console.
// In the app.js file
console.log("Output in the console by NodeJS");
Now, run the command node app.js. You should have the output in your console.
Talking about organisation, it depends of your workflow and projects. You could find lot of informations about this by reading the source code of popular projects on Github.

Resources