Please try re-compiling or re-installing Nodejs - node.js

Have upgraded our server from Ubuntu-18.04LTS to Ubuntu-20.04LTS After OS upgrade when I'm trying to start a nodejs application, but I get the below errors.
2021-11-14 10:48:01.641 - error: server-node-1: '[task-manager]
Error: The module \'/home/blruser/mibs/node_modules/weak/build/Release/weakref.node\'\nwas
compiled against a different Node.js version using\nNODE_MODULE_VERSION 57.
This version of Node.js requires\nNODE_MODULE_VERSION 64.
Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).\n at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)\n at Module.load (internal/modules/cjs/loader.js:653:32)\n
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)\n
at Function.Module._load (internal/modules/cjs/loader.js:585:3)\n
at Module.require (internal/modules/cjs/loader.js:692:17)\n
at require (internal/modules/cjs/helpers.js:25:18)\n
at bindings (/home/blruser/mibs/node_modules/bindings/bindings.js:81:44)\n
at Object.<anonymous> (/home/blruser/mibs/node_modules/weak/lib/weak.js:7:35)\n
at Module._compile (internal/modules/cjs/loader.js:778:30)\n
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)\nWARN: uncaughtException be generated\n'
$ nodejs --version
v10.19.0
How do i re-compile without losing any existing application data? Please support. Thanks.

I'm not able to ask more info in comments. But have you tried deleting your node_modules directory and installing afresh using npm install or yarn install? This would not have any impact on your application data, rather just the node modules.
But if it's an electron project or similar, try running npm i -D electron-rebuild, following that do the above mentioned step.

Related

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 running npm command on Windows: graceful-fs

I have a ReactJS project and I was trying to use some of the PrimeReact components. At some point, I faced an error (can't remember exactly which one) and I tried to run an older version of NPM in a copy of my main directory.
Now, I get this error every time, even when I run npm command.
I've already tried to delete my node_modules folder, delete my project and clone it back from GitHub and also to reinstall NodeJS several times. I don't know what to do!
I have Windows 10 and I'm using NodeJS v12.16.0.
Thanks to anyone that offers some help
Update: I have never installed gulp. I suppose that maybe some dependency is using it but, because I can't run any npm command, I can't remove them D:
The error:
C:\Users\Carlos>npm
evalmachine.<anonymous>:35
} = primordials;
^
ReferenceError: primordials is not defined
at evalmachine.<anonymous>:35:5
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\fs.js:12:1)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Module.require (internal/modules/cjs/loader.js:1043:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\graceful-fs\graceful-fs.js:3:27)
at Module._compile (internal/modules/cjs/loader.js:1157:30)
It might be an error related with gulp and node v12 conflict. If you have the gulp installed globally in your environment and you can uninstall without problems, you can try it. To help with commands, check if you have the gulp installed, typing this in your command line interface:
gulp -v
Uninstall your version:
npm uninstall -g gulp

Oops! I think I broke my work environment (nvm, npm, and node w/ angular). :(

It has been a long time since I programmed using my personal computer. I usually use a work computer. However, yesterday I decided to start working on a new pet project. Well, I went to set up the website in my Vagrant using VirtualBox, and now nvm, npm, and node are all messed up.
Every time I try to run npm install to set-up the node_module in my project, I get this error:
/home/vagrant/.nvm/v0.10.32/lib/node_modules/npm/lib/utils/unsupported.js:27
console.error(`a bug known to break npm. Please update to at least ${r
^
SyntaxError: Unexpected token ILLEGAL
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/vagrant/.nvm/v0.10.32/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object.<anonymous> (/home/vagrant/.nvm/v0.10.32/lib/node_modules/npm/bin/npm-cli.js:92:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
No matter what I try to do in npm (upgrade it, install, delete, uninstall, etc) it just throws this error.
Could somebody please help me?
The version of npm you have is not supported on Node v0.10.32. In fact Node v0.10 itself is not supported either and projects are actively dropping support it. Most dependencies will want node v4+ these days.
The version of npm you have installed will be available in the VM:
cat /home/vagrant/.nvm/v0.10.32/lib/node_modules/npm/package.json
You will need to manually extract one of the v2 or possibly even a v1 npm release over the files in /home/vagrant/.nvm/v0.10.32/lib/node_modules/npm.
Removing and setting up your nvm v0.10.32 environment again should also take npm back to a working release.
I would guess your Vagrant build does something like an npm install -g npm which would have worked at some stage but now installs the latest, incompatible version.
Use npm install -g npm#2 to stick to a v2.x release

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

NodeJS Module "userid" Error: Module version mismatch. Expected 46, got 47

I get the following error when trying to start my server.js which requires the module "userid".
module.js:460
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 46, got 47.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/root/backend/node_modules/userid/lib/userid.js:2:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
How can I solve this issue?
Not sure of the exact meaning of this error but my fix for this is to delete the node_modules directory and reinstall the required modules with npm install.
The above is a solution for this error showing up in a node project which uses locally installed modules. If there are some global modules that are throwing this error then you might have to reinstall those.
I would try upgrading the module version that causes the issue on package.json.
Another reason of this problem is that you have several different node versions installed at your system and you manage them with nvm. If you run node index.js and if you run sudo node index.js it may results in running different node version.
So if you installed your application modules with npm install and then run application with sudo node index.js you will have Module version mismatch error. In such case make sure with nvm that sudo node... run the same version of node as your application expects.
Also, while fixing initial problem you may have problem with nvm described here Can't use NVM from root (or sudo). One of possible solutions to this issue described in Yoo Matsuo's comment.

Resources