DEV Community

Iulian Preda
Iulian Preda

Posted on

Nx - Pnpm - Fixing the "pnpx" and "pnx" command

If you have used Nx with PNPM recently, you might have noticed that generating any schematics using their own "Nx Console" extension in VSCode is not working and ends up in an error like:

The term 'pnpx' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Enter fullscreen mode Exit fullscreen mode

After some research I found an easy to implement solution to fix this issue, we can just alias pnpx to pnpm exec.
The solution I will display is for powershell but you can also use a similar solution for your terminal of choice.

Aliasing PNPX

First we will need to open a powershell terminal and run the following commands. What they will do, is create a powershell file for your user that will be run on each powershell open. This file will have the authority to run remote signed scripts since we need it to have the same capabilities as the npx command.

  • new-item $PROFILE.CurrentUserAllHosts -ItemType file -Force
  • Set-ExecutionPolicy -Scope CurrentUser then RemoteSigned
  • ise $PROFILE.CurrentUserAllHosts And finally add:
function pnpx {
    $joinedArgs = $args -join " "
    pnpm exec $joinedArgs
}

function pnx{
    $joinedArgs = $args -join " "
    pnpm run nx $joinedArgs
}
Enter fullscreen mode Exit fullscreen mode
  • Save and exit

Thanks for reading!

Top comments (0)