How to uninstall a node module completely? - node.js

UPDATE
I don't have a problem with my ionic module, but with my node install(s).
It seems I have 4 node installs:
running npm start on a createreactapp installed with v15.6.0, I get:
so somehow it is using node 4.5.0.
What’s going on?
Original post:
I have a module, that is malfunctioning. Uninstalling and reinstalling it ultimately results in the same error. And I can see, that uninstalling it doesn't get rid of all the files.
Specifics:
The module in question is Ionic
The error I'm getting ever since I tried to update it is:
/usr/local/lib/node_modules/#ionic/cli/node_modules/semver/internal/re.js:1
(function (exports, require, module, __filename, __dirname) { const { MAX_SAFE_COMPONENT_LENGTH } = require('./constants')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/#ionic/cli/node_modules/semver/index.js:2:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
it is shown whenever I run an ionic command, even ionic --help
(btw. this line, that is shown from rs.js is the first line of the file)
I've tried uninstalling it with npm uninstall -g #ionic/cli
and npm uninstall -g ionic
(I also once accidentally typed npm uninstall - ionic. and it did something...)
And reinstalling it with npm install -g #ionic/cli
Tried this several times.
I've also updated node to 15.6.0.
--
I have to admit I'm generally a bit confused about node modules and where they live.
Because for Ionic there are files (I'm using MacOs 11.2.3) in /usr/local/lib/node_modules/#ionic/
But also in [user folder]/node_modules/#ionic
And there's a .ionic in the user folder.
Perhaps there is something I don't understand
How do I go about issues such as this?

Related

Cordova - ReferenceError globalThis is not defined

I am following Cordova's Getting Started guide but I'm already stuck at the 2nd step. When I try to create my project by typing cordova create myApp, it fails with the following error message:
C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova\node_modules\queue-microta
sk\index.js:5
? queueMicrotask.bind(globalThis)
^
ReferenceError: globalThis is not defined
at Object.<anonymous> (C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova
\node_modules\queue-microtask\index.js:5:25)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova
\node_modules\run-parallel\index.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
I guess it's some sort of node or npm version problem. If possible though, I would rather not install a different version of node or npm, because I'm afraid it will break other projects otherwise. My node and npm versions are as follows:
node --version
v11.15.0
npm --version
6.7.0
Just make sure to reinstall the cordova if your node version changed.
And after that, cordova prepare again.
change Node version with Node Version Manager (NVM) to Node version10.X.X.
queueMicrotask don't work with Node version 11.X.X.
https://github.com/feross/queue-microtask/issues/13

Why do I keep getting this Node SyntaxError after a while?

Can anyone help me with this SyntaxError?
I keep getting it on various paths not only mongoose, sometimes is bluebird sometimes another module.
Tried and deleted the node_modules folder and reinstall the npm modules which fixes the issue but after a couple of runs of the script, it appears again.
I honestly can't explain why it works after reinstalling the node_modules and after a few runs, it doesn't anymore.
Node: v9.8.0
NPM: 5.7.1
node_modules/mongoose/lib/options.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (module.js:613:28)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
You are having that SyntaxError because you have some broken files in your npm installations probably due to a fluctuation in your internet or any other reason. And you still got that same error after deleting the node_modules folder and re-install the npm modules again because of the same thing I said.
So your problem got fixed that last time because after you re-installed all the required dependencies ere fully installed in your node_modules.

Ember Installation Issue: SyntaxError: Use of const in strict mode

When trying to install Ember.js on Windows (and possibly other systems), after running the following commands:
npm install -g npm
npm install -g ember-cli
npm install -g bower
No errors are raised, how the command ember -v outputs the following:
C:\Users\<user>\AppData\Roaming\npm\node_modules\ember-cli\lib\cli\index.js:3
const willInterruptProcess = require('../utilities/will-interrupt-process');
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\bin\ember:26:11
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:50:13
at processDirs (C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:182:39)
This suggests an issue with my Ember installation, how can I address this?
The solution is suggested in a few other answers, for example this one, however this exact solution will not work on Windows.
Instead, the best solution is to get the latest version of Node installed via an installer.
To verify after installation try the following:
node --version
Which should output something like:
v8.9.1
Previously this command would have given a lower version number. In my case it was similar to v0.12.

Compiled with `coffee` stopped working

I'm not sure what I've done, but I can no longer compile CoffeeScript files. I keep getting the following, regardless of which file I'm trying to compile. I've tried reinstalling coffee by running sudo npm remove --global coffeescript and then sudo npm install --global coffeescript. Automatic compilation in Atom using the coffee-compile package still works. How can I resolve this?
user#computer:~/some/path $ coffee -c code.coffee
/usr/local/lib/node_modules/coffeescript/lib/coffeescript/command.js:23
({spawn, exec} = require('child_process'));
^
ReferenceError: Invalid left-hand side in assignment
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/coffeescript/bin/coffee:15:5)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
You have CoffeeScript 2+ installed, which requires Node 6 or later; but your Node runtime is < 6. (The error specifically is that the Node runtime chokes on the ({spawn, exec} = destructuring syntax, which Node < 6 doesn’t understand.) Either install CoffeeScript 1.x or Node 6+.
Got the same on Ubuntu 16.04.3 LTS, fixed simply by
$ sudo npm remove --global coffeescript
$ sudo apt-get install coffeescript

MEAN stack, cannot find module 'request'

I'm new to mean stack world, I installed mongoDB and nodejs
node -v => v4.4.3
npm -v => 2.15.1
mongo -version => MongoDB shell version: 3.2.6
then followed MEAN installation guide to install it.
after many faults I can run gult and have a response.
now when ever I try to run any command with mean, I get following error:
module.js:327
throw err;
^
Error: Cannot find module 'request'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/lib/node_modules/mean-cli/lib/controllers/anonymized-data.js:8:12)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
I tried with: sudo npm install request
but still getting same issue !! can any one guide me please? thanks in advance
UPDATE
after running command given by #Alexander Mac, I got following result
it's still same status :( . and without sudo I got lots or errors #Seth :P
Alex is right about 'request' not being part of the package. That said, instead of messing out with the install manually, it might be far easier to install a previous known good version
For e.g., you can try: sudo npm i -g mean-cli#0.12.1
mean-cli package has a bug. The authors forget to include request module in package.json: look here. You can create an issue about that on their site.
To resolve the problem locally go to /usr/lib/node_modules/mean-cli and run: sudo npm i request to install missing request module.
I use nvm to manage node.
I go to /home/ougwen1235/.nvm/versions/node/v4.2.4/lib/node_modules/mean-cli and run npm install request --save.Then, the problem was solved.

Resources