我尝试在/ home/iwan/my-project目录下使用npm安装express包:
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)
Run Code Online (Sandbox Code Playgroud)
奇怪的是npm没有在当前目录中安装快递包(/ home/iwan/my-project/node_modules/express),而是在/ home/iwan/node_modules/express中.
我错过了什么?
Bra*_*rad 49
如果当前node_modules目录中不存在该目录,NPM将在更高的目录中查找它,直到找到它为止.因此,如果父目录有一个node_modules目录,NPM将假定它是安装模块的位置.
快速解决此问题的方法是创建一个node_modules您希望放置模块的空目录.