I'm not sure what happened, but I've wasted six hours trying to fix Node.js as it just stopped working out of nowhere. Running Windows 11 with Powershell & Git Bash.
When I try to run npm install
in my local git repository with a Next.js application (which I already initialized and even deleting and initializing again), it does not work; rather, it installs my project as a package WTFF??
Whenever I run create-next-app,
it also installs the dependencies to the global folder.
node_modules
folder globally--location
flag at default startup to project
, but it still did not fix it.Please let me know if anyone has any idea, whether right or wrong. I tried looking online for related posts but couldn't find any like mine; if I overlooked any, please link them below. Thanks to anyone that helps, I have been losing my mind over this.
EDIT: When I set the flag for npm in the npm shim files, it does not work. But the workaround is to add --location=project
every time I run an npm or npx command. I know you can set an alias to make life easier. How do I fix the configuration files?
I edited the shims located in: C:\Program Files\nodejs\node_modules\npm\bin
and C:\Program Files\nodejs
I found out how to fix this problem; it had to do with a .npmrc
already existing in my User folder, which automatically added it to the npm config, or I'm assuming. All I had to do with remove the .npmrc
file in my home directory and run npm config set location=project
, and it configured itself to install to the project directory by default.
.npmrc
file existed when it should not have been there, so even though I reinstalled Node, the .npmrc
never got deleted, so it always defaulted to the old configuration file and never worked.
npm config ls
to see your configuration file; "global" config from C:\Users\Ashwi\.npmrc
npm config set location=project
--location=global
flag every time you run the command.