简体   繁体   English

缺少 node_modules 的 git checkout 项目

[英]git checkout projects with missing node_modules

What are the steps to properly checkout a project that had node_modules in .gitignore?正确检出在 .gitignore 中有 node_modules 的项目的步骤是什么? I have 2 computers.我有2台电脑。 What I've been doing is我一直在做的是

  1. From computer 1, git commit the project to GitHub从计算机 1,git 将项目提交到 GitHub
  2. On computer 2, build a blank angular project with the same name and folder structure in order to create node_modules在计算机 2 上,构建一个具有相同名称和文件夹结构的空白 angular 项目,以创建 node_modules
  3. On computer 2, clone the project from github into a different folder在计算机 2 上,将项目从 github 克隆到不同的文件夹中
  4. On computer 2, copy the src folder from github version to the blank project在2号机上,将github版本的src文件夹复制到空白项目中

It seems to be defeating the purpose of github.这似乎违背了 github 的目的。 So how do I avoid this weird approach?那么我该如何避免这种奇怪的方法呢? Is there an elegant way of cloning a project with missing dependencies (in this case node_modules)?是否有一种优雅的方式来克隆缺少依赖项的项目(在本例中为 node_modules)? I must believe there is a simple solution, but I can't seem to google the right keywords to find the solution.我必须相信有一个简单的解决方案,但我似乎无法通过谷歌搜索正确的关键字来找到解决方案。 What keyword should I be using to find this solution?我应该使用什么关键字来找到这个解决方案?

How npm works is that there is a package.json file that lists the npm packages and versions for the project. npm 的工作原理是有一个package.json文件,其中列出了项目的 npm 包和版本。 So when you clone the project, you get the package.json along with the source, sans the node_modules folder.所以当你克隆项目时,你会得到package.json和源代码,没有node_modules文件夹。 The first step you need to do is go to a command prompt and change to the directory with package.json .您需要做的第一步是转到命令提示符并切换到package.json的目录。 Then type in npm install .然后输入npm install If you have node installed correctly and added to your path, this will look at the package.json file and download the packages from the internet, creating the node_modules folder.如果您正确安装了 node 并将其添加到您的路径中,这将查看package.json文件并从 Internet 下载软件包,创建node_modules文件夹。 You could install yarn as a replacement for npm by typing npm install -g yarn .您可以通过键入npm install -g yarn来安装yarn作为 npm 的替代品。 Then you type yarn instead of npm install to create the node_modules folder.然后键入yarn而不是npm install来创建 node_modules 文件夹。

There is no need to recreate a project to create the node_modules folder, in fact that will probably cause issues because you won't have the same versions that are specified in the package.json of the repository you cloned.无需重新创建项目来创建 node_modules 文件夹,实际上这可能会导致问题,因为您不会拥有与您克隆的存储库的package.json中指定的相同版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM