Errors running ionic CLI -- how can I delete entire NPM global configuration?

I’ve been trying for three solid days to create a new ionic project. I have tons of npm cruft on my computer and I think that’s what’s causing these problems.

node v6.11.2
npm 5.3.0
ionic 3.8.1

here’s what I get when I run sudo ionic start tmp1 tabs

✔ Creating directory ./tmp1 - done!
[INFO] Fetching app base (https://github.com/ionic-team/ionic2-app-base/archive/master.tar.gz)
✔ Downloading - done!
[INFO] Fetching starter template tabs (https://github.com/ionic-team/ionic2-starter-tabs/archive/master.tar.gz)
✔ Downloading - done!
✔ Updating package.json with app details - done!
✔ Creating configuration file ionic.config.json - done!
[INFO] Installing dependencies may take several minutes!
✖ npm install - failed!
[ERROR] An error occurred while running npm install (exit code 1):

        
        npm WARN deprecated babili@0.1.2: babili has been renamed to babel-minify. Please update to babel-minify
        npm WARN deprecated babel-preset-babili@0.1.4: babili has been renamed to babel-minify. Please update to 
        babel-preset-minify
        npm WARN deprecated object-keys@0.2.0: Please update to the latest object-keys
        
        > fsevents@1.1.2 install /Users/alesh/Sites/Javascript/Javascript Projects/tmp1/node_modules/fsevents
        > node install
        
        sh: node: command not found
        
        > node-sass@4.5.3 install /Users/alesh/Sites/Javascript/Javascript Projects/tmp1/node_modules/node-sass
        > node scripts/install.js
        
        sh: node: command not found
        npm WARN ajv-keywords@2.1.0 requires a peer of ajv@>=5.0.0 but none was installed.
        npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules/fsevents):
        npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 install: `node install`
        npm WARN optional SKIPPING OPTIONAL DEPENDENCY: spawn ENOENT
        
        npm ERR! file sh
        npm ERR! code ELIFECYCLE
        npm ERR! errno ENOENT
        npm ERR! syscall spawn
        npm ERR! node-sass@4.5.3 install: `node scripts/install.js`
        npm ERR! spawn ENOENT
        npm ERR! 
        npm ERR! Failed at the node-sass@4.5.3 install script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
        
        npm ERR! A complete log of this run can be found in:
        npm ERR!     /Users/alesh/.npm/_logs/2017-08-15T11_45_31_247Z-debug.log

What I would honestly like to do is to destroy all my global npm packages and configuration and start completely from scratch. Doable without literally re-installing the OS? (When I run npm ls -g --depth-0 i get 2554 lines of output.)

npm cache clean --force

Edit: Also: do not use sudo. If you haven’t installed nvm, do that.

2 Likes

Thanks! I’d tried a million different things and I could have sworn this was one of them, but it worked. I’m still getting

[ERROR] Error: EACCES: permission denied, open '/Users/alesh/.ionic/config.json'

…when I start the ionic server, but it’s working.

This is why @AaronSterling warned you never to run ionic under sudo. chown everything under /Users/alesh/.ionic to alesh.

1 Like

That fixed it. I don’t care what those knuckleheads over on Stack Overflow say, y’all are aces. Thanks!

1 Like

Oh crap:

? The Ionic CLI has an update available (3.8.1 => 3.9.0)! Would you like to install it? Yes
✖ npm install -g ionic@latest - failed!
[ERROR] An error occurred while running npm install -g ionic@latest (exit code 243):

        
        npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/ionic/node_modules
        npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/ionic/node_modules/@ionic
        npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
        npm ERR! path /usr/local/lib/node_modules/ionic/node_modules
        npm ERR! code EACCES
        npm ERR! errno -13
        npm ERR! syscall access
        npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/ionic/node_modules'
        npm ERR!     at Error (native)
        npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/ionic/node_modules'
        npm ERR!     at Error (native)
        npm ERR!   stack: 'Error: EACCES: permission denied, access 
        \'/usr/local/lib/node_modules/ionic/node_modules\'\n    at Error (native)',
        npm ERR!   errno: -13,
        npm ERR!   code: 'EACCES',
        npm ERR!   syscall: 'access',
        npm ERR!   path: '/usr/local/lib/node_modules/ionic/node_modules' }
        npm ERR! 
        npm ERR! Please try running this command again as root/Administrator.
        
        npm ERR! A complete log of this run can be found in:
        npm ERR!     /Users/alesh/.npm/_logs/2017-08-16T15_48_15_184Z-debug.log

Probably something I broke while trying to fix the other problem. Should I chown everything in my /usr folder?

Definitely not. You should uninstall all globally installed node/npm stuff, install nvm, and use that to manage your node installations, which will all be under your home directory.

That was sort of my original question–do I have to go one by one? I’ve got hundreds of packages installed locally. (When I run npm ls -g --depth-0 i get 2554 lines of output.)

I’ve used nvm ever since I started using node, so I don’t have any direct experience with how distros package it. This looks like it may be helpful, and if you’ve installed any node/npm stuff with your package manager (such as apt-get or yum), I would uninstall via that package manager as well.

The cheap’n’easy answer is: install nvm and a new version of Node, and treat it like a partition of your disk. You don’t have to uninstall any of the old stuff. Just don’t allow it to affect your new install. Downside: lots of crap taking up disk space. Upside: you don’t have to do any work.