NPX Windows ‘get’ Error

Today I was dabbling with the WordPress plugin builder and the first step is to run npx @wordpress/create-block which seems fairly straight forward except on Windows if you have a space in your username. For example, if your Windows username is “David Millington” then you will be blasted with a page of errors that look like this:

Error: EPERM: operation not permitted, mkdir 'C:\Users\David' TypeError: Cannot read property 'get' of undefined at errorHandler (C:\Users\David Millington\AppData\Roaming\npm\node_modules\npx\node_modules\npm\lib\utils\error-handler.js:213:18)
Error: EEXIST: file already exists, mkdir 'C:\Users\David' TypeError: Cannot read property 'get' of undefined at errorHandler (C:\Users\David Millington\AppData\Roaming\npm\node_modules\npx\node_modules\npm\lib\utils\error-handler.js:213:18)

Super intuitive.

The problem is that npx is tripping up when it’s trying to write to the npm cache directory due to it failing to parse the space in the username correctly.

The fix is quite simple.

  • Open a PowerShell window and CD C:\Users
  • cmd /c dir /x
  • You should see the short version of your username directory like DAVIDM~1
  • Make a note of that and then open your npm config file. For me that was C:\Users\David Milligton\.npmrc
  • Duplicate the line similar to this one:
  • ; cache=C:\Users\David Milligton\AppData\Roaming\npm-cache
  • With the new line you made, remove the ; from the start and replace the username with the short version you got earlier on:
  • cache=C:\Users\DAVIDM~1\AppData\Roaming\npm-cache
  • Save the config file

Now if I run npx @wordpress/create-block it works as expected and the real work can begin!

Comments: None so far...be the first!

Leave a reply

Your email address will not be published. Required fields are marked *

I’m gonna wrap your legs around my head and wear you like the crown that you are.

— Francois Dillinger, Youth in Revolt