"Could not determine Node.js install directory" when running npm install - node.js

When attempting to run npm install, or when attempting to install anything through Node (like nvm) through any terminal (or in Visual Studio Code itself), I consistently get this error:
node:net:404
err = this._handle.open(fd);
^
Error: EISDIR: illegal operation on a directory, uv_pipe_open
at new Socket (node:net:404:24)
at createWritableStdioStream (node:internal/bootstrap/switches/is_main_thread:78:18)
at process.getStdout [as stdout] (node:internal/bootstrap/switches/is_main_thread:148:12)
at console.get (node:internal/console/constructor:210:42)
at console.value (node:internal/console/constructor:338:50)
at console.log (node:internal/console/constructor:377:61)
at evalScript (node:internal/process/execution:90:5)
at node:internal/main/eval_string:28:3 {
errno: -4068,
code: 'EISDIR',
syscall: 'uv_pipe_open'
}
Node.js v18.13.0
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\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
Could not determine Node.js install directory
I have reinstalled node.js, npm, WSL, and Visual Studio Code multiple times attempting to fix the issue. I have also followed the suggested solutions here, here, and here to no avail. I have ensured that node and npm are added to my PATH as well in the environment variables. So far I've had no luck attempting to fix this solution. What else can I try? Are there any steps I could be missing?

I believe the issue was due to a corrupt installation of ubuntu itself, not node or WSL. Reinstalling ubuntu as a whole seemed to do the trick.

Related

npm start not working windows - 'MODULE_NOT_FOUND', requireStack: []

I am trying to learn react JS, and in the video the user runs the command npx create-react-app filename.
They then cd into the file that has been created and then run the command npm start.
Whenever I run this command I get the following error in the terminal:
at Module._resolveFilename (node:internal/modules/cjs/loader:1060:15)
at Module._load (node:internal/modules/cjs/loader:905:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
Any help is greatly appreciated, I have tried uninstalling and reinstalling node.js and have tried a few different versions, regardless I always get the same error.
I have tried to reinstall and change versions of node.js and it did not work. I also tried running the command in a few different directories and this also did not work.

Error : cannot find module npmlog (required by npmcli)

I was trying to install some dependancies for jupyter with npm, so it works with javascript. I am currently having trouble, anything I do with npm throws this error :
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'npmlog'
Require stack:
- /usr/share/npm/bin/npm-cli.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at /usr/share/npm/bin/npm-cli.js:22:13
at Object.<anonymous> (/usr/share/npm/bin/npm-cli.js:153:3)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/share/npm/bin/npm-cli.js' ]
}
This same error pops whenever I try to use npm, for anything, even npm version throws it.
I have tried removing npm, nodejs and all their dependancies and installing it again with apt-get, I have also tried to do what was advised in this old issue. I tried using nvm. I tried deleting the usr/bin/node before reinstalling node.
Even this command threw the same error :
npm install -g npm#3.5.4
It might help to know I work on linux mint ? Nothing helped, this error is still there, I can't use npm and I don't understand what's going on... Does anyone has any idea on why that might happen ?
Thank you for your time and have a nice day.
Try clear the npm cache by running npm cache clean --force. This can help resolve issues caused by corrupted cache data.
If you are using linux, make sure you have the correct permissions to install npm packages. You may need to run the command with sudo.

truffle init node:internal/modules/cjs/loader:936

I wanted to create my own NFT collection so I bought a course called "The Complete NFT Web Development Course - Zero To Expert
". In that course you need to use truffle. I installed all what I sopposed to need but when I try to type truffle init it gives me an error. I used npm install also in this process and it gaves me an error related to react, but I don't think that it's the problem. I have a package.json downloaded from the github repositorie that the teacher have.
Versions:
npm: '8.3.1',
node: '16.14.0'
Windows 10
Error:
truffle init
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\Usuario\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js'
[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)[39m
[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)[39m
[90m at node:internal/main/run_main_module:17:47[39m {
code: [32m'MODULE_NOT_FOUND'[39m,
requireStack: []
}
Try reinstalling truffle. If you reinstall truffle you will get upgraded version. And that might solve your problem.
Installing truffle version 5.4.29 install -g truffle#5.4.29 in the command prompt and got a message to run npm audit fix --force.
Then inside vscode inside terminal I ran truffle init and got the "sweet " message. I suppose the version matters.

error could not determine Node.js install directory

I have tried to install ionic by doing npm install ionic
ionic start myapp blank does not work and since then any npm commands tells me :
$ npm config
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module 'C:\Users\dandonneau.m\devc\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769: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: []
}
Could not determine Node.js install directory
I had the same error because I was using a too new version of Node for my system.
I have Windows 7.
The last officially tested version of Node on Windows 7 is 13.6.0 (source). Although, you can also try to run newer versions such as 15.8.0 (source).
The bug occurred when I tried to use Node version 17.1.0.
Solution
I solved the problem by downgrading the Node version to 15.8.0 (in my case via nvm, you can just re-install).
You can also try upgrading your operating system.

Trying to access node REPL produces Error: Cannot find module 'esm'

I'm using Kubuntu 20.04.1 and I just installed the current version of node trough nvm (14.8.0), now when trying to access the node REPL by just typing node, I got this error message:
$ node
internal/modules/cjs/loader.js:1083
throw err;
^
Error: Cannot find module 'esm'
Require stack:
- internal/preload
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
at Function.Module._load (internal/modules/cjs/loader.js:923:27)
at Module.require (internal/modules/cjs/loader.js:1140:19)
at Module._preloadModules (internal/modules/cjs/loader.js:1397:12)
at loadPreloadModules (internal/bootstrap/pre_execution.js:446:5)
at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:74:3)
at internal/main/repl.js:19:1 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'internal/preload' ]
}
Any advice about what's going on and how to fix it is welcome
I'm answering my own question in the event someone else faces the same problem: To access the node REPL just install the esm package globally:
npm install -g esm
Or if just require the packae for a project, whitin yout project folder:
npm i esm
For more informatiĆ³n check this link.

Resources