本地安装与全局安装的NPM模块 [英] Locally installed versus globally installed NPM modules

查看:89
本文介绍了本地安装与全局安装的NPM模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 package.json 文件中,我将Bower列为依赖项。运行 npm install 后,凉亭将在本地安装。当我尝试在本地安装bower后运行它时,出现错误

In my package.json file, I have bower listed as a dependency. After I run npm install, bower gets installed locally. When I try to run bower after installing it locally I get an error


bower未被识别为内部或外部命令

"bower" is not recognized as an internal or external command

解决此问题的唯一方法似乎是在全球安装凉亭。我为什么要这样做?如果我的项目包含Bower的本地副本,为什么不使用节点呢?

It seems the only way to resolve this is to install bower globally. Why should I have to do this? If my project contains a local copy of bower, why won't node use it?

推荐答案

在本地安装会使Bower可用于当前项目(将所有节点模块存储在 node_modules 中)。通常这仅适用于使用这样的模块,例如 var module = require('module'); 不能作为命令使用该外壳程序可以解析,直到在全局范围内安装它为止 npm install -g module ,其中npm将其安装在您的路径变量可以解析此命令的位置。

Installing locally makes bower available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.

编辑: 此文档对其进行了详尽的解释。

This documentation explains it pretty thorougly.

这篇关于本地安装与全局安装的NPM模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆