节点全局或本地安装包
Node install packages globaly or locally
我在本地安装了 create-react-app 包。但它没有用。当我使用 -g
在全球范围内安装它时,它起作用了。
我遇到了其他几个软件包,其中一些在全局安装时有效,但在本地安装时无效,反之亦然。
某人如何知道要在全局或本地安装特定软件包?
使用 npx create-react-app
,这将下载 React Cli
,并在创建项目后从您的本地系统中删除 Cli
。
npm 将首先扫描项目中的本地 node_module 文件夹,如果找到包则使用它,否则它会上树并在全局包中搜索。
所有项目依赖都可以全局使用,也可以在项目本地使用。
但在这种情况下 create-react-app
用作 shell 工具而不是项目依赖项,因此它必须在 PATH 环境变量中。
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
试试这个,希望这能解决问题。
我认为这不应该发生。您可以按照此文档了解 全局与本地设置:
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
- npm是一个主要用来安装包的工具
- npx 是一个执行包的工具。
这是什么意思?如果你想执行一个包而不在你的计算机上安装它然后启动它你可以直接使用 npx 。例如;
- create-react-app is an utility to bootstrap a react project.
- if you use it with npx ( npx create-react-app my-app ) you will have your my-app project in place without the need to install create-react-app itself.
- npm install create-react-app and then create-react-app my-app if you use npm
我在本地安装了 create-react-app 包。但它没有用。当我使用 -g
在全球范围内安装它时,它起作用了。
我遇到了其他几个软件包,其中一些在全局安装时有效,但在本地安装时无效,反之亦然。
某人如何知道要在全局或本地安装特定软件包?
使用 npx create-react-app
,这将下载 React Cli
,并在创建项目后从您的本地系统中删除 Cli
。
npm 将首先扫描项目中的本地 node_module 文件夹,如果找到包则使用它,否则它会上树并在全局包中搜索。
所有项目依赖都可以全局使用,也可以在项目本地使用。
但在这种情况下 create-react-app
用作 shell 工具而不是项目依赖项,因此它必须在 PATH 环境变量中。
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
试试这个,希望这能解决问题。
我认为这不应该发生。您可以按照此文档了解 全局与本地设置:
https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/
- npm是一个主要用来安装包的工具
- npx 是一个执行包的工具。
这是什么意思?如果你想执行一个包而不在你的计算机上安装它然后启动它你可以直接使用 npx 。例如;
- create-react-app is an utility to bootstrap a react project.
- if you use it with npx ( npx create-react-app my-app ) you will have your my-app project in place without the need to install create-react-app itself.
- npm install create-react-app and then create-react-app my-app if you use npm