node.js - Gulp 安装在项目根目录之外

标签 node.js laravel npm gulp node-modules

我在新项目中安装 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/

相关文章:

javascript - Express:将 res.json 作为参数传递时出错

php - Laravel NotFoundHttpException 路由

php - laravel 4 eloquent 中的生命周期回调

node.js - 从 package.json 中的源代码编译

node.js - npm 审核 EINVALIDTAGNAME

npm - 为什么我必须运行 "npm install"两次才能成功安装我的包

node.js - 如何在 Node cron 作业中使用请求/响应

javascript - node.js 嵌套 http req 对象未定义 - bodyParser.urlencoded({ 扩展 : true } not working

node.js - 显示由nodejs中的express提供的图像

php - 如何扩展/修改现有的 Laravel Nova 字段?