Why does VsCode NPM throw a module not found error? - node.js

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.

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

New to node.js found a possible PATH variable error

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.

Can't run node module geojson-polygon-labels on Windows

I've download the package from "https://github.com/andrewharvey/geojson-polygon-labels/", ran "npm-install" and the node-modules folder was successfully created:
folder - screenshot
However, when cd to bin folder and run "geojson-polygon-labels < v.geojson > v_label.geojson", it throws the eror: "not recognized as internal or external command, operable program or batch file".
I'm really confused at this point. On github it's not really well-documented how to use this tool, and I'm quite new to Node too.
Please help me. Thanks!
Edit: I've tried install it on Ubuntu (subsystem on Windows 10) then run "geojson-polygon-labels" from the bin folder. The same error occured.
Edit2: I figured out to how properly run the tool. On Ubuntu I ran:
./geojson-polygon-labels < polygon.geojson > labels.geojson
However, now a new error pops out:
/home/lamnguyen/geojson-polygon-labels-master/bin/geojson-polygon-labels:25
turf.featureEach(flatInputGeoJSON, (feature) => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
What should I do now?
Edit 4: A friend of mine ran it on a "real" Ubuntu with a small sample file and it worked out. Maybe tomorrow I've give a shot :)
In this package I've set up the bin property in the package.json https://docs.npmjs.com/files/package.json#bin so when you run npm install it knows what scripts are executables. You might need to set up your PATH in your shell to the directory NPM installs the binaries to. Or use the full or relative path as you've found out.
The Unexpected Token > message seems like you're running an older version of node which doesn't support ES6 arrow functions, so try upgrading your version of node?

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?

Resources