Skip to content

Instantly share code, notes, and snippets.

@christophervigliotti
Last active April 12, 2022 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophervigliotti/7827912e379376fe3fbbe81e190333c0 to your computer and use it in GitHub Desktop.
Save christophervigliotti/7827912e379376fe3fbbe81e190333c0 to your computer and use it in GitHub Desktop.
When you cannot run npm commands...rebuild it

The Issue 😕

When I attempt to execute command npm i I am getting the following...

The Error 🥔

parallels@ubuntu-linux-20-04-desktop:~/Documents/Code/angular-complete-guide-routing$ sudo npm -i
[sudo] password for parallels: 
node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module 'code-point-at'
Require stack:
- /usr/lib/node_modules/npm/node_modules/wide-align/node_modules/string-width/index.js
- /usr/lib/node_modules/npm/node_modules/wide-align/align.js
- /usr/lib/node_modules/npm/node_modules/gauge/lib/render-template.js
- /usr/lib/node_modules/npm/node_modules/gauge/lib/plumbing.js
- /usr/lib/node_modules/npm/node_modules/gauge/lib/index.js
- /usr/lib/node_modules/npm/node_modules/npmlog/lib/log.js
- /usr/lib/node_modules/npm/lib/utils/log-shim.js
- /usr/lib/node_modules/npm/lib/utils/exit-handler.js
- /usr/lib/node_modules/npm/lib/cli.js
- /usr/lib/node_modules/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/wide-align/node_modules/string-width/index.js:3:19)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/lib/node_modules/npm/node_modules/wide-align/node_modules/string-width/index.js',
    '/usr/lib/node_modules/npm/node_modules/wide-align/align.js',
    '/usr/lib/node_modules/npm/node_modules/gauge/lib/render-template.js',
    '/usr/lib/node_modules/npm/node_modules/gauge/lib/plumbing.js',
    '/usr/lib/node_modules/npm/node_modules/gauge/lib/index.js',
    '/usr/lib/node_modules/npm/node_modules/npmlog/lib/log.js',
    '/usr/lib/node_modules/npm/lib/utils/log-shim.js',
    '/usr/lib/node_modules/npm/lib/utils/exit-handler.js',
    '/usr/lib/node_modules/npm/lib/cli.js',
    '/usr/lib/node_modules/npm/bin/npm-cli.js'
  ]
}

The Solution 💡

With help from https://github.com/spiraldev/ and https://gist.github.com/ted-piotrowski/33d7a23ce9f67231620d8edd825bf89e

# uninstall the things
sudo apt-get remove nodejs
sudo apt-get remove npm
sudo rm /etc/apt/sources.list.d/*

# install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# close and reopen terminal now or...
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# verify installation
command -v nvm

# made a VM snapshot at this point

# next steps...
# https://dev.to/ms314006/how-to-install-npm-through-nvm-node-version-manager-5gif
# nvm use system ... no system version defined

nvm ls-remote
# revealed latest LTS: v16.14.2   (Latest LTS: Gallium)

nvm install v16.14.2

# check the version of nvm currently in use 
nvm current

# let's install this stuff...
ng i
# getting this...
# npm WARN old lockfile 
# npm WARN old lockfile The package-lock.json file was created with an old version of npm,
# npm WARN old lockfile so supplemental metadata must be fetched from the registry.
# npm WARN old lockfile 
# npm WARN old lockfile This is a one-time fix-up, please be patient...
# npm WARN old lockfile 

ng s
# we are gtg!

Also at https://github.com/christophervigliotti/angular-complete-guide-routing#solution

Why? 🤷

Because https://gist.github.com/christophervigliotti/92e5b3b93cbe9d630d8e9d81b7eb6636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment