Unable to delete node_modules folder - node.js

I am trying to delete the node modules folder from my project so that I can rerun npm i as there were errors when I was running my npm scripts (I think node_modules corrupted), but I don't seem to be able to.
I've tried:
Deleting via right clicking in Windows explorer. This just doesn't do anything.
In VS Code right clicking and selecting 'Delete Node Modules', which produces the following message:
I think the node modules file has corrupted - there only seems to be 3 folders in there, all of which I can't delete.
If I run npm i I get the following:

Try to reboot windows with SAFE MOOD.
I face the same issue on windows 10. I could delete it when I have been in a safe mood on windows.
Don't know really an issue on windows or my hard drive.

Related

Desktop.ini files breaking node_modules

I have a create-react-app project that works well. However, if I let it sit for a couple days—without making any changes—it always breaks, with the error
package.json » eslint-config-react-app/jest#overrides[0]:
Environment key "jest/globals" is unknown
I'm convinced this is because desktop.ini files get created, and somehow they mess up the loading process of the dependencies. The problem gets fixed if I delete the whole node_modules folder and reinstall it using npm install. But the newly installed dependencies only last a couple of days (until the new desktop.ini files get regenerated) before they again break.
I've tried to stop windows from producing the desktop.ini files using the registry, but windows didn't listen (I run Windows 11). I've also seen that it is not recommended to delete/suppress these files.
Has anyone dealt with this issue? Are there any manageable workarounds?

How do I restore npm root folder to the default one?

I just installed ionic with npm and when I run -v to check the version it gives me an error and that says "ionic is not recognized as an internal or external command". Basically it's like I never installed the package in the first place. After a while I figured that my default folder for npm has changed.
I'm using Windows 10 so I think it should be something like
User\MyUser\AppData\npm\node_modules" or maybe "User\MyUser\AppData\Roaming\npm\node_modules" but for whatever reason npm installs stuff inside "AppData\Local
I asked around a bit (even here on stackoverflow) and found out that if I edit the environmental variable "PATH" things should work, so I did it and ionic now works fine
However today I tried to install express and the same error popped up. I checked my PATH again just to be sure and it's pointing to the "Local" folder where my node_modules are. Ionic still works right now and it's in the same folder, so I have no idea why express doesn't work.
I want to fix things once and for all, how do I change the place where the node_modules are? How do I go back to AppData or Roaming or whatever folder Windows 10 uses by default?

Why does VS 2017 set node_modules folder to read only in .Net Core App?

I'm building a .Net Core application using Angular for my client-side code. For the most part, I'm using the default template that is included in VS 2017. For whatever reason, VS is making my node_modules folder read only. Before I was able to install packages via command line in the directory that holds my client side code as well as my package.json file and my node_modules folder. Before I was able to do this, but now it is defaulting the folder to read only which is invaliding all of my npm commands. I've verified that this is the case because I can remove the read only attribute via windows explorer and then run any of my commands like npm install.
Has anyone else encountered this before? If so, what did you do to resolve this?
Thanks!
Okay, I found the answer. VS puts a lock on the node_modules folder while it is running.
So, I guess for now if you need to add packages just close VS first.

Nodejs serverless Windows 10

I have a serverless nodejs project which was working just fine. Did not touch it for a week, wanted to re-deploy it and now I'm greeted with the following errors:
1) EPERM: operation not permitted, scandir ‘D:\GIT\awesome.build\node_modules’
2) EEXIST: file already exists, symlink ‘D:\GIT\awesome\node_modules’ -> ‘D:\GIT\awesome.build\node_modules’
First off I get the first error. If I try for a second time I get the second one. If I delete .build I'm back to receiving the first.
I know that during the idle week I did get the spring Windows update.
Windows 10 17134.48
NPM 6.1.0
Nodejs 8.11.1
Any ideas what could be causing this?
Updated Answer
We've identified and found the issue relating to this. We have published a new NPM module specifically with this fix and created a PR on the original plugin (but he hasn't updated it in ages)
Fixed Version
https://www.npmjs.com/package/#hewmen/serverless-plugin-typescript
Original Answer:
We're running into the exact same issue. Multiple serverless projects, multiple computers. We've tried different node versions as well. Completely wiping fetched repo and redoing it. We've tried using elevated consoles. No idea what's going on, but we're getting that exact same error on all our stuff across 3 different machines.
Current suspicion is Windows did an update recently that hosed it.. but I figured we'd see more info on it.
However, we did find a workaround for this.
Delete your current '.build' and '.serverless' folders inside the root project area
In command prompt, run 'sls package' and let it fail with the same error
Manually copy over 'node_modules' and 'package.json' from the root directory into the .build folder (delete the ones in there). This won't cause the error saying the .build directory already exists which you might have seen fighting this.
In command prompt, run 'sls deploy' (or 'sls package' if you only want to package)
Not ideal... but it got us deploying again until we figure out the real issue.
The issue seems to be in the way the symbolic link is created for node_modules inside the '.build' folder. It's linking a directory, but seems to be treating it as a file all of a sudden for whatever reason. In windows if you use "mklink" without the '/D' option on a directory, it will give you the same result we see in the '.build' folder. If you do the mklink /D - you don't have this issue.
This is why our current suspicion is a Windows update. Because everything was working perfectly fine, then all projects across all our Windows PCs stopped. We've rolled back our repos to stuff we've successfully deployed, and no issues. We've attempted to re-deploy projects we haven't touched in months, same issue.
It's very annoying to say the least. I will update this if we find out what's wrong.

Node modules folder gets corrupted and requires everytime I restart the computer

I have my nodejs projects on my google drive folder.. When I starts a project it works fine.. but when I restart the computer and run the project again, an error of cannot find module ... happens , every time different module is missing.
Running npm install doesn't help, only deleting the whole node_modules folder and reinstalling it works but the same will happen after I restart my computer.
Any help or suggestion ?

Resources