简体   繁体   English

当我已经在node_module文件夹中拥有所有依赖项时,为什么必须运行'npm install'

[英]Why is it necessary to run 'npm install' when I already have all the dependence in node_module folder

Why is it necessary to run 'npm install' when I already have all the dependence in node_module folder. 当我已经在node_module文件夹中拥有所有依赖项时,为什么需要运行“ npm install”。

After running 'npm install' successfully on my machine, I want to setup same project on another machine, why do I require run 'npm install' again when I already have downloaded all the dependence in node_module folder? 在我的机器上成功运行'npm install'之后,我想在另一台机器上设置相同的项目,为什么我已经在node_module文件夹中下载了所有依赖项,为什么还需要再次运行'npm install'?

npm install extract all your dependencies from your package.json, download it and save them in your node_modules folder. npm install从package.json中提取所有依赖项,下载并保存在node_modules文件夹中。 You don't need to run npm install again and again if you already have installed all your dependencies locally. 如果您已经在本地安装了所有依赖项,则无需一次又一次地运行npm install。

When ever you installs a new dependency you run npm install <package-name> --save and why --save for the first time? 每当安装新的依赖项时,都运行npm install <package-name> --save ,为什么要第一次--save because it adds the new installed dependency on your package.json. 因为它会在package.json上添加新安装的依赖项。 We never push node_modules to our git repo only the updated package.json is pushed to repo. 我们绝不会将node_modules推送到git仓库中,而只会将更新的package.json推送到仓库中。 In that case if a new person pulls your code from the repo he is only going to run npm install and all the dependencies mentioned on your package.json will going to available on his project locally. 在这种情况下,如果一个新人从回购中提取您的代码,他将只运行npm install而package.json中提到的所有依赖项都将在他的本地项目中可用。 Thats a small intro about why we use package.json hope it helps. 那就是关于为什么使用package.json的一个简短介绍,希望对您有所帮助。

First of all I want to inform you 2 things: 首先,我想通知您两件事:

  • As your project depend on some packages (node_modules), same as some packages are dependent on other packages. 由于您的项目依赖于某些软件包(node_modules),因此与某些软件包一样,它们依赖于其他软件包。
  • when we install some package with command npm install package -g then -g will install it in global folder which can be accessed by any project. 当我们使用命令npm install package -g安装某些软件包时,-g会将其安装在可以被任何项目访问的全局文件夹中。 by using -g, package is not added to node_modules. 通过使用-g,程序包不会添加到node_modules。

Now here is answer of your problem. 现在,这是您的问题的答案。 There might be possible that some dependencies of packages are installed as global on one machine and not on other one. 软件包的某些依赖项可能会全局安装在一台计算机上,而不是另一台计算机上。 This can happen as developers work on many project on same machine and might be they have installed global packages. 当开发人员在同一台机器上处理多个项目时,可能会发生这种情况,并且可能是因为他们已经安装了全局软件包。 So in this case you need to execute npm install command. 因此,在这种情况下,您需要执行npm install命令。

Check the version of node in both system . 检查两个系统中的节点版本。
I guess that would be issue. 我想那是个问题。 you local system would have either higher version than the server. 您的本地系统将具有比服务器更高的版本。
May be not able to compile for higher version make sure the version are same for node in both , to reduce the comflict. 可能无法编译为更高版本,请确保两个节点的版本都相同,以减少冲突。

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

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