能否复制GitLab远程node_modules文件夹并获取指定旧版本模块文件夹?
Hey there! Let's walk through the practical ways you can get hold of that original old-version module folder from your GitLab project:
Check your local Git repository history
First up, if the oldnode_modulesfolder (or the specific module subfolder) was actually committed to Git (note: this isn't a best practice, but some teams do it), you can dig into your commit history:- Run
git log --onelineto browse past commits and pinpoint the one where the old module version was present. - Use
git checkout <commit-hash> -- path/to/your/node_modules/<module-name>to pull that specific folder from the historical commit into your working directory. - Important: If your team never committed
node_modules(the standard approach), this method won't work.
- Run
Leverage npm/yarn's local cache
Both npm and yarn store cached copies of every module version you've ever installed locally. Here's how to access it:- For npm:
- Run
npm view <module-name> versionsto list all available versions of the module, so you can confirm the exact old version number. - Check if the old version is in your cache with
npm cache ls <module-name>@<old-version>. - If it exists, navigate to your npm cache directory (usually
~/.npmon Linux/macOS, or%AppData%\npm-cacheon Windows), find the compressed package for that version, and extract it to get the original module folder.
- Run
- For yarn:
- Run
yarn cache dirto get the path to your yarn cache folder. - Use
yarn cache list <module-name>@<old-version>to verify if the old version is cached. - Locate the cached package and extract it just like with npm.
- Run
- For npm:
Check GitLab CI/CD artifacts or cache
If your GitLab project uses CI/CD pipelines, there's a chance the oldnode_modulesfolder was saved as a pipeline artifact or stored in the CI/CD cache:- Head to your GitLab project's CI/CD > Pipelines page, look for past pipelines that ran when the old module version was in use.
- Check if those pipelines have artifacts containing
node_modules, or if the cache is still retained (cache retention depends on your project's CI/CD settings).
Reinstall the old version to a temporary directory
If none of the above methods work, you can simply reinstall the old version in a temporary location to get the original folder:- Run these commands in your terminal:
mkdir temp-old-module && cd temp-old-module npm init -y npm install <module-name>@<old-version> - The original module folder will be in
temp-old-module/node_modules/<module-name>— you can copy it wherever you need from there.
- Run these commands in your terminal:
内容的提问来源于stack exchange,提问作者user3808307

