运行 npm install create-react-app 创建的 node_modules 文件夹有什么用?

What for is the node_modules folder that is created by running npm install create-react-app for?

当我在任何文件夹中 运行 npm install create-react-app 时,它会创建一个 node_modules 文件夹。 node_modules 文件夹有什么用?它与 create-react-app 有什么关系?

简答:是。

长答案:create-react-app 应该全局安装,然后 运行 在您希望放置应用程序的文件夹中。

create-react-app 应使用 npm install -g create-react-app 安装,这将使 create-react-app 命令在任何目录中可用。

有关 npm 创建或写入的各种文件夹的完整说明,请参阅 npm documentation

当你 运行 npm install create-react-app (没有全局 (-g) 修饰符) npm 执行本地依赖安装并将结果放在当前目录的 ./node_modules .

基本上是包含你的应用程序需要的所有节点包的文件夹,nmp install create-react-app依赖于其他节点包将安装在node_modules文件夹中。

如果您想避免创建 node_modules 目录,您可以通过 npm install -g create-react-app 进行全局安装。