error could not determine Node.js install directory - node.js

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.

Related

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

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.

generating new nestjs module results in Error: Failed to execute command

I'm using MacOS monterey with M1 chip as my operating system. installed NestJS cli using this command: sudo npm install -g #nestjs/cli
when creating new nest project using nest new message everything works fine, but when I try to create new module using this command nest generate module messages I face error.
why does this happen? I tried installing schematics using npm i -g #nestjs/schematics, I don't know if I should've installed it but this didn't help anyway.
The error I face is:
/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338
throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
^
Error: Unknown argument skipImport. Did you mean skip-import?
at parseArgs (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338:19)
at main (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:122:49)
at Object.<anonymous> (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:367:5)
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)
at node:internal/main/run_main_module:17:47
Failed to execute command: node #nestjs/schematics:module --name=messages --no-dry-run --no-skipImport --language="ts" --sourceRoot="src" --spec.
worth noting that I don't face any issues when I do the same thing on ubuntu 20 or 22
Quick solution:
add this to your nest-cli.json
"root": "src"
change into the src of your project folder
cd src
run
nest generate module messages
if the above does not work also try changing the version of packages in package.json to
"#nestjs/cli": "8.2.6",
"#nestjs/schematics": "8.0.11",
removing the node modules in the current project
reinstalling the nest cli with
npm uninstall -g #nestjs/cli
npm i -g #nestjs/cli#8.2.6
this is a bug on the latest version of #nestjs/cli (v8.2.7). Downgrade it to 8.2.6 and it will work (I tested it). It was reported here: https://github.com/nestjs/nest-cli/issues/1693
Also, I don't recommend using the global version of the CLI. Instead, use npx nest or yarn nest.

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.

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.

Node Module Version Mismatch: Expected 50

I've had this problem where, from a brand new installation of Node and npm, the serial port package won't load with the following error in the Hello World Electron package:
I am on Node version 6.6.0 and NPM version 3.10.7 and OS X 10.11.6.
I looked to see if I was somehow out of date, but looking at this list, I can't find anything that has a module version of 50. Is this a bug?
I have tried npm rebuild, as well as removing modules and reinstalling, but no dice.
Update: even though when I run node -v it prints v6.6.0, running process.versions.node in the web console gives me v6.5.0. What's going on here?
This is a known issue which is caused by the serialport module using native code that is built for a different version of Node. You can read a bit more about addons here, if you're interested; they're just modules written in C/C++ that can interface with Node so the module can interface with the hardware more easily.
The solution proposed by that issue is this:
npm rebuild --runtime=electron --target=1.2.5 --disturl=https://atom.io/download/atom-shell --build-from-source
If you've not already installed electron-rebuild, that might be helpful to ensure that the rebuilding process works correctly:
npm install --save-dev electron-rebuild
even though when I run node -v it prints v6.6.0, running process.versions.node in the web console gives me v6.5.0. What's going on here?
Electron uses its own version of Node that isn't connected to your system Node installation (see the homepage to view the Node version that the latest Electron uses, or use process.versions.node, like you did in the question).
You could try an older version (perhaps 1.1.0, which uses Chrome 50?) in case that is the cause of the issue.
In my case the error was:
App threw an error during load
Error: Module version mismatch. Expected 50, got 48.
at Error (native)
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
at Object.Module._extensions..node (module.js:583:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/myapp/node_modules/sqlite3/lib/sqlite3.js:4:15)
After rebuilding error was fixed:
npm install --save-dev electron-rebuild
npm rebuild --runtime=electron --target=1.4.3 --disturl=https://atom.io/download/atom-shell --build-from-source

Resources