truffle init node:internal/modules/cjs/loader:936 - node.js

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.

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.

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.

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.

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