当前位置:   article > 正文

nrm镜像源管理工具及常见报错_nrm删掉镜像仓库

nrm删掉镜像仓库

1. nrm 介绍

  • nrm 是 Node.js 的镜像管理小工具,可以方便地查看镜像源列表和管理这些镜像源,并且可以快速地切换到最适合当前网络环境的镜像源。

2. 安装

  • 全局安装 npm i nrm -g

3. 常用命令

  • 查看当前可用的镜像源列表: nrm ls

  • 切换镜像源 :nrm use <registry>nrm use <url>

    • <registry> 是镜像源名称,<url> 是镜像源的地址
    • 例如切换到淘宝:nrm use taobaonrm use https://registry.npm.taobao.org/
  • 添加新的镜像源:nrm add <registry> <url>

    • 例如:nrm add test http://test.com/
  • 删除镜像源 :nrm del <registry>

  • 测试镜像源速度:nrm test

  • 显示当前使用的镜像源:nrm current

  • 查看源列表时,当前源的名称前面带*号,也可以用于查看当前镜像源

  • 打开指定镜像源的网站首页nrm home <registry>

  • 显示 nrm 命令的帮助信息nrm help

3. 常见报错

  • nrm ls 报错如下:

    • 原因:由于 nrm 的依赖模块 open 采用的是 ES Module 的方式,但是 nrm 自身是一个 CommonJS 模块,无法直接加载 ES Module 的依赖

    • 解决:先注释掉报错文件的第9行(按照路径查找文件,如果使用的编辑器终端可以用 ctrl + 鼠标左键 点击报错文件直接跳转),再将 require('open') 改为 import('open'),具体修改如下:

      // 找到 onHome 函数并修改
      // 源代码
      function onHome (name, browser) {
          var allRegistries = getAllRegistry();
          var home = allRegistries[name] && allRegistries[name].home;
          if (home) {
              var args = [home];
              if (browser) args.push(browser);
              open.apply(null, args);
          }
      }
      
      // 修改为
      function onHome(name, browser) {
          var allRegistries = getAllRegistry();
          var home = allRegistries[name] && allRegistries[name].home;
          if (home) {
            var args = [home];
            if (browser) args.push(browser);
            import('open')
              .then((module) => {
                var open = module.default;
                open(...args);
              })
              .catch((error) => {
                console.error(error);
              });
          }
        }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
  • nrm ls 显示镜像源列表后,当前源的前面不带*

    • 再次打开刚才的cli.js文件,修改代码如下,把&&修改为||,具体如下:
        // 源代码
        config(attrs, registry).then(() => {
            console.log('                        ');
             const newR = npm.config.get(FIELD_REGISTRY);
             var customRegistries = getCustomRegistry();
             Object.keys(customRegistries).forEach(key => {
                 delete customRegistries[key][FIELD_IS_CURRENT];
             });
             if (hasOwnProperty(customRegistries, name) && (name in registries || customRegistries[name].registry === registry.registry)) {
                 registry[FIELD_IS_CURRENT] = true;
                 customRegistries[name] = registry;
             }
             setCustomRegistry(customRegistries);
             printMsg(['', '   Registry has been set to: ' + newR, '']);
         }).catch(err => {
             exit(err);
         })
        
        // 修改后
        config(attrs, registry).then(() => {
            console.log('                        ');
             const newR = npm.config.get(FIELD_REGISTRY);
             var customRegistries = getCustomRegistry();
             Object.keys(customRegistries).forEach(key => {
                 delete customRegistries[key][FIELD_IS_CURRENT];
             });
             if (hasOwnProperty(customRegistries, name) || (name in registries || customRegistries[name].registry === registry.registry)) {
                 registry[FIELD_IS_CURRENT] = true;
                 customRegistries[name] = registry;
             }
             setCustomRegistry(customRegistries);
             printMsg(['', '   Registry has been set to: ' + newR, '']);
         }).catch(err => {
             exit(err);
         })
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号