This seemed to solve the issue for me:
- Go to folder C:\Program Files\nodejs
- You have to edit four files named npm, npm.cmd, npx, npx.cmd
- Open the files in a text editor, like Visual Studio Code
- Replace prefix -g with prefix –location=global in all four files
- Save all (if asked, save as administrator)