coreybutler / nvm-windows

A node.js version management utility for Windows. Ironically written in Go.
MIT License
37.28k stars 3.32k forks source link

[Issue]: Why did my Anaconda folder get deleted after installing NVM on Windows? All my environments are gone! #1130

Closed maxin9966 closed 5 months ago

maxin9966 commented 5 months ago

What happened?

Why did my Anaconda folder get deleted after installing NVM on Windows? All my environments are gone!

What did you expect to happen?

Why did my Anaconda folder get deleted after installing NVM on Windows? All my environments are gone!

Version

1.1.11 or newer (Default)

Which version of Windows?

No response

Which locale?

None

Which shell are you running NVM4W in?

No response

User Permissions?

Administrative Privileges, Elevated

Is Developer Mode enabled?

None

Relevant log/console output

No response

Debug Output

Why did my Anaconda folder get deleted after installing NVM on Windows? All my environments are gone!

Anything else?

No response

maxin9966 commented 5 months ago

I'm really devastated.

coreybutler commented 5 months ago

This is nowhere near enough info to troubleshoot. There is only one occasion where NVM for Windows deletes anything: when you run the nvm uninstall command, it removes the vX.X.X folder for that version of Node.js. Nothing is removed without the user explicitly running a command.

Anaconda is a Python utility. NVM for Windows doesn't touch Python.

maxin9966 commented 5 months ago

This is nowhere near enough info to troubleshoot. There is only one occasion where NVM for Windows deletes anything: when you run the nvm uninstall command, it removes the vX.X.X folder for that version of Node.js. Nothing is removed without the user explicitly running a command.

Anaconda is a Python utility. NVM for Windows doesn't touch Python.

Version 1.1.12.0 nvm-setup.exe My computer is installed with node16 through conda. I want to install node18, so I try to use nvm.

During the installation of nvm, the nvm setup prompts me whether to take over node16. I chose yes, and after the nvm installation is complete, the conda command immediately becomes invalid. This entire process lasted for about two and a half minutes, and I was in front of the computer all the time. It was definitely a problem with nvm, and I had not realized that the anaconda folder had been deleted. After I uninstalled nvm, I only found out that the entire anaconda folder had disappeared.

maxin9966 commented 5 months ago

Oh my god, I lost dozens of my conda environments, this is terrible.

maxin9966 commented 5 months ago

This is nowhere near enough info to troubleshoot. There is only one occasion where NVM for Windows deletes anything: when you run the nvm uninstall command, it removes the vX.X.X folder for that version of Node.js. Nothing is removed without the user explicitly running a command.

Anaconda is a Python utility. NVM for Windows doesn't touch Python.

I am using Windows 11.

It took a long time to uninstall the NVM program. It's possible that during the uninstallation of NVM, a bug might have caused NVM to delete Anaconda.

coreybutler commented 5 months ago

It sounds like you're trying to use two version managers simultaneously (conda and nvm4w). These tools aren't explicitly designed to work with each other. They each assume control (which is par for the course with all node version managers).

When NVM4W tries to take control of a Node version, it just moves the Node root directory. It doesn't attempt to move other directories that aren't related to Node.js, and it will not move directories it cannot access. This is why the README very clearly recommends removing prior versions of Node before installing NVM4W:

image

I do not know how Anaconda operates, and I'm sorry you lost your conda directories. There is a very real chance those directories still exist in their original location, or in the recycle bin, but I don't know how conda works with Node installs.

@tedpatrick - do you have any insights into how conda handles files with Node?

maxin9966 commented 5 months ago

The file was probably ordered to be deleted (not sent to the recycle bin), and unfortunately, I hadn't backed up this computer's data to the NAS. It's alright, I've accepted the outcome. I should have blamed myself for not backing up promptly.

coreybutler commented 5 months ago

@maxin9966 I pinged Ted via Slack (ex-Anaconda). He said the conda environments are located in the following directories:

C:\Users\$USERNAME\miniconda3\envs
C:\Users\$USERNAME\Anaconda3\envs

Most likely your environments still exist in one of these locations.

He also had the following to say:

Sounds like the path reference to node was changed (conda env to node within) not the environments themselves.

Conda is sort of a larger environment as it covers both python and any binary

My thought is:
1. His environments are perfectly intact, they were dereferenced not deleted.
2. If NVM, they need to remove node from conda else that reference will not work.

In his case, the path to node was the path to conda.

Finally, he recommended using an environment.yml file.

maxin9966 commented 5 months ago

@coreybutler The folder C:\Users\$USERNAME\anaconda3, along with its contents, has been completely lost. I am referring to the version of Anaconda3 from the second half of 2022.

The installation of NVM was quick, and immediately after installing it, the conda command vanished (I'm not sure if the Anaconda3 folder was still present at this point). Then, I tried to uninstall NVM, which took a considerable amount of time, around 10 minutes, during which I momentarily thought the uninstallation process had frozen. My assumption is that the Anaconda3 folder was deleted during this uninstallation period.

coreybutler commented 5 months ago

Sorry, I don't know enough to comment on versions of Anaconda. However; if conda stored directories inside the node install root, then NVM4W probably did move them to the new location... and then yes, if you uninstalled NVM4W entirely, then it probably nuked that directory when the installation was deleted.

maxin9966 commented 5 months ago

@coreybutler It could be due to removing the anaconda3 folder with nvm, perhaps coincidentally or for some other undetermined reason. I hope others don't face this problem. Regardless, I'm very grateful for your response. I must hurry to recreate my environment.

coreybutler commented 5 months ago

Again, I'm sorry you're facing this frustration. If you ever find out what happened, let me know. If I know what the issue is, I could probably put a warning of some kind into NVM4W to prevent this for other conda users.

tedpatrick commented 5 months ago

@maxin9966 To recreate/manage a conda environment best to use an environment.yml

environment.yml

name: my_cool_environment
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.12.2
  - pip=24.0
  - pip:
    - boto3==1.34.38

create an environment in a directory with environment.yml

conda env create

update environment in directory with environment.yml

conda env update

activate environment anywhere - "my_cool_environment" comes from environment.yml

conda activate my_cool_environment
maxin9966 commented 5 months ago

@tedpatrick Thank you.

maxin9966 commented 5 months ago

@coreybutler image As shown in the image, I found that the 'envs' folder inside anaconda3 has been moved here, these three environments were not completely removed (there should have been more than a dozen virtual environments in the 'envs' folder, but only three were left), and at the time of the incident, these three environments were in use, so there were still some files left in the environment that were not completely removed. Why would nvm move the anaconda3 'envs' folder here? This should be considered a bug.

coreybutler commented 5 months ago

NVM4W isn't aware of anaconda, so it doesn't recognize any specific folder as an "Anaconda directory". When NVM4W assumes control of an existing Node install, it moves the entire v16.19.0 directory to NVM_HOME. That's the parent of the node.exe file (and node_modules). The standard way Node is installed assumes the directory is dedicated to Node. This is how the official installers operate as well.

From a Node perspective, additional directories in the installation folder are allowed, but most don't have special meaning (aside from node_modules). It assumes these directories are for node purposes. The fact they are for conda is ignored by Node (and NVM4W).

NVM4W tries to adhere to the effects you'd see if there were no version manager. It doesn't care about environments, but moves the directories under the assumption they provide value to the Node installation the user has configured. Environments are on our roadmap for Runtime, but they aren't related to conda's, so there's no specific intention of supporting conda at this time. That said, I'm glad to be aware of how conda is operating so we may be able to smooth transitions for users. Maybe some kind of interoperability could be considered in the future.

maxin9966 commented 5 months ago

Great (thumbs up emoji), it's advisable to default to retaining the previously installed Node during NVM uninstallation, , just to be on the safe side.

maxin9966 commented 5 months ago

I have reinstalled Conda and NVM without linking Node this time, and everything is working fine now. Thank you.