This is a output of a few frustrating hours (spanning over a few days – as and when I can get time), and finally got it fixed and working. Hopefully it might help someone who is also dealing with npm blues.
When NodeJS and npm works, its awesome. But when it borks, it is worst than my code or so it seems :).
Been playing with a few things and wanting to get a dashboard going with Grafana (and InfluxBD as a time-series DB). But some of the installation was failing and for the life of me, could not figure out why and how. Clean image install and downgrading to the previous stable version also didn’t help.
One example of npm failing miserably was the “Error: Method not Allowed” which is not very helpful. Here is an example of what I was seeing:
root@pi-server:/var/lib/grafana/plugins/grafana-trackmap-panel# npm install (node:4538) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. npm ERR! Error: Method Not Allowed npm ERR! at errorResponse (/usr/share/npm/lib/cache/add-named.js:260:10) npm ERR! at /usr/share/npm/lib/cache/add-named.js:203:12 npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:167:7) npm ERR! at FSReqWrap.oncomplete (fs.js:135:15) npm ERR! If you need help, you may report this *entire* log, npm ERR! including the npm and node versions, at: npm ERR! <http://github.com/npm/npm/issues> npm ERR! System Linux 4.19.57-v7+ npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" npm ERR! cwd /var/lib/grafana/plugins/grafana-trackmap-panel npm ERR! node -v v8.11.1 npm ERR! npm -v 1.4.21 npm ERR! code E405 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /var/lib/grafana/plugins/grafana-trackmap-panel/npm-debug.log npm ERR! not ok code 0 root@pi-server:/var/lib/grafana/plugins/grafana-trackmap-panel#
Again, like I said not very helpful. But I finally got to be able to fix it and move on. And here is what worked for me, and it seems like in the OS image, there was a corrupted files, at some level. In most cases you need root access.
Step 1: – Remove and clean up NodeJS.
sudo apt-get remove nodejs nodejs-legacy nodered
Step 2: Get the latest stable source.
curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash - sudo apt-get install -y nodejs npm install -g npm@latest\
I also noticed sometimes the commands above don’t work. If that is the case then then try the following, to get the latest.
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - sudo apt-get install -y nodejs npm install -g npm@latest
And based on your dependencies, v9 might not work and you need v8 then you change the first line as following Or for the latest:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs npm install -g npm@latest
And finally in the end install and start.
npm install && npm start
And if you do need to check for the update and get the latest, then try:
sudo npm install -g npm@latest