Wrangler dev error - could not install wranglerjs dependencies

MacOS Big Sur
Node v14.16.1 (via nvm)

When I run wrangler dev I get the following error:

❯ wrangler dev              
thread 'main' panicked at 'could not install wranglerjs dependencies: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }

', src/wranglerjs/mod.rs:309:39
stack backtrace:
   0:        0x105c67874 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha0848bb2602b5d05
   1:        0x105c8d830 - core::fmt::write::h9f3ccac2ef682b93
   2:        0x105c5f016 - std::io::Write::write_fmt::h0a47673aab280496
   3:        0x105c69b39 - std::panicking::default_hook::{{closure}}::h850c6aaf5e80c2f5
   4:        0x105c697fd - std::panicking::default_hook::h037801299da6e1c6
   5:        0x105c6a1bb - std::panicking::rust_panic_with_hook::h76436d4cf7a368ac
   6:        0x105c69ce5 - std::panicking::begin_panic_handler::{{closure}}::h516c76d70abf04f6
   7:        0x105c67ce8 - std::sys_common::backtrace::__rust_end_short_backtrace::h653290b4f930faed
   8:        0x105c69c4a - _rust_begin_unwind
   9:        0x105cb239f - core::panicking::panic_fmt::hde9134dd19c9a74f
  10:        0x105cb22a5 - core::result::unwrap_failed::hcef4aa8b48b8f381
  11:        0x1053f1a3c - wrangler::wranglerjs::setup_build::h9943ba5c64c99adb
  12:        0x1053ef68d - wrangler::wranglerjs::run_build::h795e7c25658145c7
  13:        0x1054b20b6 - wrangler::build::build_target::hfe30cf03d62930f8
  14:        0x10561d828 - wrangler::commands::dev::dev::h86ac07a2849da2fb
  15:        0x105355a3e - wrangler::run::hfb5a5ea4f4511340
  16:        0x10534b928 - wrangler::main::h9189d008b4c83f56
  17:        0x10535cd7a - std::sys_common::backtrace::__rust_begin_short_backtrace::hf0a370fd48888819
zsh: abort      wrangler dev

I am able to run sudo wrangler dev and it works okay, but it creates dist and ‘worker’ folders in my project with ‘root’ as the owner.

The wrangler binary was manually installed in my /usr/local/bin folder with the following permissions: ‘[email protected] 1 tony admin 15334280 15 Apr 14:03 wrangler’

I can’t seem to get rid of this error regardless of the various methods of installing Wrangler globally via Node/NPM (Official PKG, Brew, N, NVM varients) or manually.

I need help!

Found the answer from the good folks on the wrangler discord channel. It turns out that under ~/Library/Caches/.wrangler I had wranglerjs files installed as the root user. I deleted the .wrangler directory and ran wrangler dev again. All sorted.