Getting Past The Cloudflare Wrangler CLI NPM Installer Errors

Update: If this is an option for you, an easier approach is to use cargo to install the Wrangler CLI. If you’ve tried installing via NPM already, clear out any existing files by running npm uninstall -g @cloudflare/wrangler.

In trying to install the Cloudflare Wrangler CLI via npm, I first pasted in exactly as the documentation said:

npm i @cloudflare/wrangler -g

This threw a long list of errors, with a recommendation at the bottom of the list saying:

npm ERR! The operation was rejected by your operating system.

npm ERR! It is likely you do not have the permissions to access this file as the current user

npm ERR! 

npm ERR! If you believe this might be a permissions issue, please double-check the

npm ERR! permissions of the file and its containing directories, or try running

npm ERR! the command again as root/Administrator.

Seeing this, I threw a sudo in before the command, only to be greeted with this error message:

{

  errno: -13,

  syscall: 'mkdir',

  code: 'EACCES',

  path: '/Users/[USERNAME]/.wrangler'

}

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! @cloudflare/[email protected] postinstall: `node ./install-wrangler.js`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the @cloudflare/[email protected] postinstall script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Squinting at the message, I saw that the installer had failed to create a directory named “.wrangler” in my home directory. So I pulled up a new terminal window and ran the mkdir .wrangler command myself.

Running the sudo install command again, I instead got this:

{

  errno: -13,

  syscall: 'mkdir',

  code: 'EACCES',

  path: '/Users/[USERNAME]/.wrangler/bin'

}

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! @cloudflare/[email protected] postinstall: `node ./install-wrangler.js`

npm ERR! Exit status 1

npm ERR! 

npm ERR! Failed at the @cloudflare/[email protected] postinstall script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Progress, yes, but another mkdir issue. So I repeated what I did and created a “bin” directory within the “.wrangler” directory I had just created. This did the trick and the installation completed successfully.

The Terminal output showing Cloudflare Wrangler was successfully installed via npm. What follows is a transcription of the raw output. /usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js > @cloudflare/wrangler@1.19.0 postinstall /usr/local/lib/node_modules/@cloudflare/wrangler > node ./install-wrangler.js Downloading release from https://workers.cloudflare.com/get-npm-wrangler-binary/1.19.0/x86_64-apple-darwin wrangler has been installed! + @cloudflare/wrangler@1.19.0 added 22 packages from 9 contributors in 1.851s
The Terminal output showing Cloudflare Wrangler was successfully installed via npm.

In short: Run mkdir yourself to create a “.wrangler” directory within your home directory. Then create a “bin” directory within that “.wrangler” directory you created.