2016-07-07 153 views
0

要在當前目錄中安裝package.json的軟件包,您需要運行npm install命令。如何在特定目錄中安裝npm軟件包

是否有可能安裝軟件包在特定的文件夾package.json,沒有去到該文件夾​​`

的閨房,然後一飲而盡任務已經找到解決辦法:

bower install --config.cwd=<directory> 
gulp build --cwd <directory> 

但缺少類似功能的npm

當我運行命令:npm install --prefix C:\Users\ng\Projects\Lottery\src\SPA 我看到一個錯誤:

npm ERR! addLocal Could not install C:\Users\ng\Projects 
npm ERR! Windows_NT 10.0.10586 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--prefix" "C:\\Users\\ng\\Projects\\Lottery\\src\\SPA" 
npm ERR! node v6.2.1 
npm ERR! npm v3.9.3 
npm ERR! code EISDIR 
npm ERR! errno -4068 
npm ERR! syscall read 

npm ERR! eisdir EISDIR: illegal operation on a directory, read 
npm ERR! eisdir This is most likely not a problem with npm itself 
npm ERR! eisdir and is related to npm not being able to find a package.json in 
npm ERR! eisdir a package you are trying to install. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\ng\Projects\npm-debug.log 

而且從documentation

The prefix config defaults to the location where node is installed. On most systems, this is /usr/local. On windows, this is the exact location of the node.exe binary

+1

[如何將npm安裝到指定目錄?](http://stackoverflow.com/questions/14469515/how-to-npm-install-to-a-specified-directory) –

+0

@anshumansingh modified我的問題來解釋問題 – Uriil

回答

1

這應該是解決方案:How to npm install to a specified directory?

基本上你正在使用的前綴選項與全局選項一起:npm install --prefix <path/to/prefix_folder> -g

你也可以有看看documentation

+0

您可能沒有寫權限。嘗試使用文件夾,例如在你的桌面上。 – nidhoeggr09

+0

您是否使用-g選項? – nidhoeggr09

+0

該文檔說:「當設置全局標誌時,npm會在這個前綴中安裝東西,當它沒有設置時,它會使用當前包的根目錄,或者當前的工作目錄(如果不在包中)。 – nidhoeggr09