Global npm install failing with ERR_INVALID_ARG_TYPE after fnm usage

I’m stuck with a weird npm problem. Everything was fine yesterday but today I can’t run my dev server. When I try npm run dev, it fails without any error message. I tried the usual fixes:

  • Deleting node_modules and package-lock.json
  • Reinstalling dependencies
  • Uninstalling and reinstalling Node.js
  • Checking my PC’s environment variables
  • Using fnm (Fast Node Manager) to manage Node versions

Nothing worked. I even tried to switch to Yarn, but I can’t install it either. The error I’m getting is:

ERR_INVALID_ARG_TYPE: The 'file' argument must be of type string. Received undefined

I’m out of ideas. Has anyone faced this issue before? Any suggestions on how to fix it? I can share my package.json if needed.

hey mate, had similar probs. try this:

check ur npm config. run npm config ls -l in terminal. look for weird paths or settings. if u see anything off, reset it with npm config delete <setting>.

also, make sure ur PATH is clean. sometimes old node stuff hangs around. gl!

I’ve dealt with this exact issue before, and it’s usually related to path conflicts when using multiple Node version managers. Here’s what worked for me:

First, completely remove fnm from your system. Then, check your PATH environment variable and remove any fnm-related entries. You might need to restart your terminal or even your computer after this.

Next, reinstall Node.js from the official website, choosing the LTS version for stability. After installation, open a new terminal and run node -v and npm -v to ensure they’re working correctly.

If the issue persists, try running npm config set prefix /usr/local to reset npm’s global installation directory. Finally, consider using nvm instead of fnm to avoid similar conflicts in the future.

I’ve encountered a similar issue before, and it turned out to be related to fnm interfering with my global npm configuration. First, I completely uninstalled fnm and reverted to my system’s default Node installation. Then, I cleared my npm cache using npm cache clean --force and manually deleted any residual npm-related folders in my user directory.

Next, I reinstalled Node.js from the official website, ensuring that npm was installed with it. After a system restart, I ran npm doctor to verify that everything was correctly set up. This process resolved the ERR_INVALID_ARG_TYPE error for me.

If the problem persists, consider checking if antivirus software might be interfering with npm’s file operations.