node.js 安装好之后,运行npm -v 时出现错误

node.js安装好之后,在dos命令下输入node -v正常;

clipboard.png

但是输入nmp -v时就出现错误了

clipboard.png

下面是错误日志:(npm-debug.log)
    0 info it worked if it ends with ok
    1 verbose cli [ 'D:\\Program Files\\nodejs\\node.exe',
    1 verbose cli   'D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli   'install',
    1 verbose cli   '-g',
    1 verbose cli   'cnpm',
    1 verbose cli   '–registry=https://registry.npm.taobao.org' ]
    2 info using npm@2.15.1
    3 info using node@v4.4.3
    4 verbose install initial load of C:\Users\Administrator\AppData\Roaming\npm\package.json
    5 verbose readDependencies loading dependencies from C:\Users\Administrator\AppData\Roaming\npm\package.json
    6 silly cache add args [ 'cnpm', null ]
    7 verbose cache add spec cnpm
    8 silly cache add args [ '–registry=https://registry.npm.taobao.org', null ]
    9 verbose cache add spec –registry=https://registry.npm.taobao.org
    10 silly cache add parsed spec Result {
    10 silly cache add   raw: 'cnpm',
    10 silly cache add   scope: null,
    10 silly cache add   name: 'cnpm',
    10 silly cache add   rawSpec: '',
    10 silly cache add   spec: 'latest',
    10 silly cache add   type: 'tag' }
    11 silly addNamed cnpm@latest
    12 verbose addNamed "latest" is being treated as a dist-tag for cnpm
    13 info addNameTag [ 'cnpm', 'latest' ]
    14 silly mapToRegistry name cnpm
    15 silly mapToRegistry using default registry
    16 silly mapToRegistry registry https://registry.npmjs.org/
    17 silly mapToRegistry data Result {
    17 silly mapToRegistry   raw: 'cnpm',
    17 silly mapToRegistry   scope: null,
    17 silly mapToRegistry   name: 'cnpm',
    17 silly mapToRegistry   rawSpec: '',
    17 silly mapToRegistry   spec: 'latest',
    17 silly mapToRegistry   type: 'tag' }
    18 silly mapToRegistry uri https://registry.npmjs.org/cnpm
    19 verbose addNameTag registry:https://registry.npmjs.org/cnpm not in flight; fetching
    20 silly cache add parsed spec Result {
    20 silly cache add   raw: '–registry=https://registry.npm.taobao.org',
    20 silly cache add   scope: null,
    20 silly cache add   name: null,
    20 silly cache add   rawSpec: '–registry=https://registry.npm.taobao.org',
    20 silly cache add   spec: 'D:\\–registry=https:\\registry.npm.taobao.org',
    20 silly cache add   type: 'local' }
    21 error addLocal Could not install D:\–registry=https:\registry.npm.taobao.org
    22 verbose request uri https://registry.npmjs.org/cnpm
    23 verbose request no auth needed
    24 info attempt registry request try #1 at 09:57:51
    25 verbose request id baf8c862cfcdd3ef
    26 verbose etag W/"59fa7e79-28fb1"
    27 verbose lastModified Thu, 02 Nov 2017 02:10:01 GMT
    28 http request GET https://registry.npmjs.org/cnpm
    29 http 304 https://registry.npmjs.org/cnpm
    30 verbose headers { date: 'Tue, 14 Nov 2017 01:53:46 GMT',
    30 verbose headers   via: '1.1 varnish',
    30 verbose headers   'cache-control': 'max-age=300',
    30 verbose headers   etag: 'W/"59fa7e79-28fb1"',
    30 verbose headers   age: '175',
    30 verbose headers   connection: 'keep-alive',
    30 verbose headers   'x-served-by': 'cache-nrt6124-NRT',
    30 verbose headers   'x-cache': 'HIT',
    30 verbose headers   'x-cache-hits': '1',
    30 verbose headers   'x-timer': 'S1510624427.596870,VS0,VE0',
    30 verbose headers   vary: 'Accept-Encoding, Accept' }
    31 silly get cb [ 304,
    31 silly get   { date: 'Tue, 14 Nov 2017 01:53:46 GMT',
    31 silly get     via: '1.1 varnish',
    31 silly get     'cache-control': 'max-age=300',
    31 silly get     etag: 'W/"59fa7e79-28fb1"',
    31 silly get     age: '175',
    31 silly get     connection: 'keep-alive',
    31 silly get     'x-served-by': 'cache-nrt6124-NRT',
    31 silly get     'x-cache': 'HIT',
    31 silly get     'x-cache-hits': '1',
    31 silly get     'x-timer': 'S1510624427.596870,VS0,VE0',
    31 silly get     vary: 'Accept-Encoding, Accept' } ]
    32 verbose etag https://registry.npmjs.org/cnpm from cache
    33 verbose get saving cnpm to C:\Users\Administrator\AppData\Roaming\npm-cache\registry.npmjs.org\cnpm\.cache.json
    34 verbose correctMkdir C:\Users\Administrator\AppData\Roaming\npm-cache correctMkdir not in flight; initializing
    35 silly addNameTag next cb for cnpm with tag latest
    36 silly addNamed cnpm@5.1.1
    37 verbose addNamed "5.1.1" is a plain semver version for cnpm
    38 silly cache afterAdd cnpm@5.1.1
    39 verbose afterAdd C:\Users\Administrator\AppData\Roaming\npm-cache\cnpm\5.1.1\package\package.json not in flight; writing
    40 verbose correctMkdir C:\Users\Administrator\AppData\Roaming\npm-cache correctMkdir not in flight; initializing
    41 verbose afterAdd C:\Users\Administrator\AppData\Roaming\npm-cache\cnpm\5.1.1\package\package.json written
    42 verbose stack Error: ENOENT: no such file or directory, open 'D:\–registry=https:\registry.npm.taobao.org'
    42 verbose stack     at Error (native)
    43 verbose cwd D:\
    44 error Windows_NT 6.1.7601
    45 error argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "cnpm" "–registry=https://registry.npm.taobao.org"
    46 error node v4.4.3
    47 error npm  v2.15.1
    48 error path D:\–registry=https:\registry.npm.taobao.org
    49 error code ENOENT
    50 error errno -4058
    51 error syscall open
    52 error enoent ENOENT: no such file or directory, open 'D:\–registry=https:\registry.npm.taobao.org'
    52 error enoent This is most likely not a problem with npm itself
    52 error enoent and is related to npm not being able to find a file.
    53 verbose exit [ -4058, true ]
阅读 11.1k
7 个回答

是不是局部安装了

path 修改路径的问题,具体度娘上有教程

将npm的路径添加到环境变量(如:C:UsersAdministratorAppDataRoamingnpm 具体路径需要自己电脑确认),然后重启cmd

一般做法,
1.重启电脑,特别是设计到环境变量的
2.使用npm cache clean --force清除缓存
3.使用npm install npm -g,重新安装npm
4.以上方法都不行,重装nodejs

环境变量的问题,配置npm的环境变量

Windows 下安装的时候,注意勾选 “Add to PATH”,在选择安装目录的那一页。

另外题主,现在已经是 8.9.4 了,你装 4.x 版本太旧了……

1、添加环境变量,具体自己百度,特别多教程;
2、要不然就先切换到node.js的目录下,如:“cd C:Program Filesnodejs”,然后再执行“node -v”;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题