[英]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
我一直在做的是
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.