本地安装与全局安装的 NPM 模块 [英] Locally installed versus globally installed NPM modules
问题描述
在我的 package.json
文件中,我将 bower 列为依赖项.在我运行 npm install
之后,bower 会在本地安装.当我在本地安装后尝试运行 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.为什么我必须这样做?如果我的项目包含 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');
它不能作为 shell 可以解析的 command 使用,直到你全局安装它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.
本文档 解释得很透彻.
这篇关于本地安装与全局安装的 NPM 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!