update-notifier/index.js:58 Unexpected token

Sebastian Rogers
1 min readMar 16, 2021

--

If you are using the Azure Cloud Shell and the CLI for Microsoft 365 then you may be encountering this error when you try and use it

/usr/local/lib/node_modules/@pnp/cli-microsoft365/node_modules/update-notifier/index.js:58
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@pnp/cli-microsoft365/dist/index.js:17:28)

For example

m365 login

Its caused by the fact that Cloud Shell use Node LTS Version 8 by default and the CLI for Microsoft needs a higher version. You shouldn’t install a higher version over the top of the existing one as apparently soame parts of Cloud Shell still need version 8.

Simple solution install NVM and then you can set the version you’ll need to do it for each shell you use.

Then just use m365.

Bash

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashexport NVM_DIR="$HOME/.nvm"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"nvm install node

PowerShell

Install-Module nvmInstall-NodeVersion 15Set-NodeVersion 15

As the Cloud Shell is Linux based you need to explicitly set the version each session.

--

--

Sebastian Rogers
Sebastian Rogers

Written by Sebastian Rogers

Technical Director for Simple Innovations Ltd. First paid for code in 1980, but still has all his own hair.

Responses (1)