NPM 在当前目录外安装包 [英] NPM Installs Package Outside Current Directory

查看:58
本文介绍了NPM 在当前目录外安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从/home/iwan/my-project 目录中使用 npm 安装 express 包:

I try to install express package using npm from inside /home/iwan/my-project directory:

npm install express

express@3.3.7 ../node_modules/express
├── methods@0.0.1
├── cookie-signature@1.0.1
├── range-parser@0.0.4
├── fresh@0.2.0
├── buffer-crc32@0.2.1
├── cookie@0.1.0
├── debug@0.7.2
├── send@0.1.4 (mime@1.2.11)
└── commander@1.2.0 (keypress@0.1.0)

奇怪的是 npm 没有在当前目录(/home/iwan/my-project/node_modules/express)中安装 express 包,而是在/home/iwan/node_modules/express 中.

The strange thing is npm doesn't install express package in current dir (/home/iwan/my-project/node_modules/express), but in /home/iwan/node_modules/express.

我错过了什么吗?

推荐答案

如果 node_modules 目录在您当前目录中不存在,NPM 将在更高的目录中寻找它,直到找到它.因此,如果父目录有一个 node_modules 目录,NPM 将假定它是安装模块的位置.

If the node_modules directory doesn't exist in your current directory, NPM will look for it in the higher directories until it finds it. So, if the parent directory has a node_modules directory, NPM will assume that's where it is to install modules.

解决这个问题的一个快速方法是创建一个空的 node_modules 目录,您希望在其中放置模块.

A quick way around this is to create an empty node_modules directory where you want the modules to be placed.

这篇关于NPM 在当前目录外安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆