为什么node_modules文件夹没有提交给Git? [英] Why is the node_modules folder not committed to Git?
问题描述
当我使用
yo angular
$创建一个AngularJS项目时p $ p>
它创建一个node_modules /目录,但将该目录放在.gitignore中。当我在其他地方复制项目并运行时,
grunt服务器
我得到
致命错误:无法找到本地grunt。
如果您看到此消息,则找不到Gruntfile,或者
grunt未在本地安装到您的项目中。有关安装和配置grunt的更多
信息,请参阅
入门指南:
入门但是如何处理缺少的node_modules /目录,指南并没有说明什么。
node_name /目录缺失故意,因为yeoman将它放入.gitignore中。
在这种情况下使用Yeoman和Grunt的正确方法是什么?
是否有更好的Yeoman和Grunt文档?
谢谢。
解决方案这是正确的行为。
node_modules
的内容并不意味着被提交给源代码控制。 npm 背后的想法是它跟踪一个名为的package.json 。这个文件应该被提交到源代码控制。然后在另一台机器上,你可以签出代码并运行。
npm install
这将查看package.json文件并从云中下载所有必需的文件,并将它们全部放入新的
node_modules
目录中。When I create an AngularJS project with
yo angular
it creates a node_modules/ directory but puts that directory in .gitignore. When I clone the project elsewhere and run
grunt server
I get
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide:
The getting started guide doesn't say anything about how to handle the missing node_modules/ directory however.
The node_modules/ directory is missing deliberately because yeoman put it in .gitignore.
What's the right way to use Yeoman and Grunt in this case?
Is there some better documentation for Yeoman and Grunt?Thanks.
解决方案That is the correct behaviour. The contents of
node_modules
is not meant to be committed to source control. The idea behind npm is that it tracks all required node dependencies in a file called package.json. This file should be committed to source control. Then on a different machine, you can check out the code and run
npm install
This looks at the package.json file and downloads all required files from the cloud and puts them all into a new
node_modules
directory.这篇关于为什么node_modules文件夹没有提交给Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!