我在新项目中安装 Gulp 时遇到了一个奇怪的问题。
假设我有以下路径:
c:/development/myproject
当我在该目录中运行npm install gulp
时,node_modules文件夹实际上是在
c:/development/node_modules
而不是
c:/development/myproject/node_modules
所有 gulp 插件也安装在我的项目根目录之外的该目录中。
我还有一个早期的项目,之前已经安装了 gulp,当我尝试在该项目目录中重新运行 gulp 安装时,它已正确安装在项目根目录中(例如:c:/development/myolderproject/node_modules
),而不是外部。
我认为这与本案没有任何关系,但新项目使用的是 Laravel 4,而另一个项目使用的是 Laravel 5。
我不记得之前必须设置任何特定配置,所以我完全困惑为什么它的行为不同。
最佳答案
当您执行npm install
时,它从父目录中找到package.json
并认为它是包根目录。
相关文档:https://www.npmjs.org/doc/files/npm-folders.html#more-information
Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)
If no package root is found, then the current folder is used.
关于node.js - Gulp 安装在项目根目录之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26956573/