我试图用npm list -g
列出我的全局包,但输出中没有模块。我可以通过ls ~/npm/lib/node_modules/
手动查看文件系统中的所有全局模块,npm prefix -g
设置为~/npm/lib
。有趣的是,sudo npm list -g
仅在~/.nvm/v6.2.0/lib/node_modules
下显示我的模块,这只是“npm”模块。如何使用npm list -g
显示所有全局模块?
以下是我收到的输出示例:
[my-pc]/home/folder$ npm root -g -ddd
npm info it worked if it ends with ok
npm verb cli [ '/home/me/.nvm/v6.2.0/bin/node',
npm verb cli '/home/me/npm/bin/npm',
npm verb cli 'ls',
npm verb cli '-g',
npm verb cli '-ddd' ]
npm info using npm@3.9.2
npm info using node@v6.2.0
/home/me/npm/lib/node_modules
npm verb exit [ 0, true ]
npm info ok
[my-pc]/home/folder$ npm prefix -g -ddd
npm info it worked if it ends with ok
npm verb cli [ '/home/me/.nvm/v6.2.0/bin/node',
npm verb cli '/home/me/npm/bin/npm',
npm verb cli 'prefix',
npm verb cli '-g',
npm verb cli '-ddd' ]
npm info using npm@3.9.2
npm info using node@v6.2.0
/home/me/npm
npm verb exit [ 0, true ]
npm info ok
[my-pc]/home/.../folder$ sudo npm ls -g --depth=0
/home/me/.nvm/v6.2.0/lib
└── npm@3.9.3
[my-pc]/home/.../folder$ npm ls -g --depth=0
<no output>
[my-pc]/home/.../folder$ sudo npm outdated -g --depth=0
Package Current Wanted Latest Location
npm 3.9.3 3.9.3 3.9.2
up
[my-pc]/home/.../folder$ ll ~/.nvm/v6.2.0/lib/node_modules/
total 12
drwxr-xr-x 3 me me 4096 May 23 15:31 ./
drwxr-xr-x 3 me me 4096 May 17 12:40 ../
drwxr-xr-x 12 nobody me 4096 May 23 15:31 npm/
[my-pc]/home/.../folder$ ll ~/npm/lib/node_modules/
total 92
drwxrwxr-x 20 me me 4096 May 23 15:39 ./
drwxrwxr-x 3 me me 4096 Feb 17 2015 ../
drwxr-xr-x 4 me me 4096 Apr 18 00:43 bower/
drwxr-xr-x 5 me me 4096 Apr 17 12:12 dat/
drwxr-xr-x 6 me me 4096 Jun 18 2015 grunt-cli/
drwxr-xr-x 6 me me 4096 Jun 25 2015 gulp/
drwxr-xr-x 9 me me 4096 Dec 5 03:08 jaws-framework/
drwxr-xr-x 10 me me 4096 May 18 13:38 learnyounode/
drwxr-xr-x 7 me me 4096 May 18 01:36 mapshaper/
drwxr-xr-x 6 me me 4096 Nov 6 2015 modulus/
drwxr-xr-x 8 me me 4096 Apr 6 2015 node-inspector/
drwxr-xr-x 5 me me 4096 Mar 9 15:51 node-rest-client/
drwxr-xr-x 11 me me 4096 May 23 15:39 npm/
drwxrwxr-x 5 me me 4096 Feb 17 2015 nvm/
drwxr-xr-x 3 me me 4096 May 25 2015 package-info/
drwxr-xr-x 3 me me 4096 Sep 16 2015 peerflix/
drwxr-xr-x 9 me me 4096 May 18 11:02 scope-chains-closures/
drwxr-xr-x 8 me me 4096 May 23 15:23 serverless/
drwxr-xr-x 6 me me 4096 Apr 7 2015 stream-adventure/
drwxr-xr-x 3 me me 4096 Apr 28 2015 superlevel/
如上所示,我使用NVM作为我的节点版本管理器,这可能会导致这种混淆。但是如何让npm list -g
正确列出我全局安装的软件包?
BTW,我在本地安装的软件包与npm list
一起列好。
答案 0 :(得分:1)
我最近在Node v10和npm v6上遇到了这个问题。
npm list -g
返回
-- (empty)
问题是Node环境正在生产中。使用此命令检查:
echo $NODE_ENV
矿井处于生产。
我将其更改为开发并且有效。
export NODE_ENV=development
答案 1 :(得分:0)
在我的情况下,echo $ NODE_ENV返回空白,但是当我nano ~/.npmrc
列出时:
production=true
env=production
我删除了两个文件,然后重新运行npm list -g
,瞧!