• lerna publish时报错 E401 [UNAUTHORIZED] Login first


    问题描述

    运行命令yarn release-log,报错如下

    lerna http fetch PUT 401 https://registry.npmmirror.com/picture-hot-zone 602ms
    lerna ERR! E401 [UNAUTHORIZED] Login first
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    
    • 1
    • 2
    • 3
    • 4

    截图

    yarn release实际上是运行的lerna publish --conventional-commits

    解决方案

    使用npm run release-log进行发布


    项目场景

    使用dumi生成文档,使用fatehr-build打包,使用lerna管理包和发布组件

    根目录package.json文件

    {
      "private": true,
      "name": "tds-components",
      "version": "1.0.0",
      "scripts": {
        "start": "dumi dev",
        "docs:build": "dumi build",
        "docs:deploy": "gh-pages -d docs-dist",
        "build": "father-build",
        "release-log": "lerna publish --conventional-commits",
        "release-no": "lerna publish --conventional-commits --no-verify-access",
        "deploy": "npm run docs:build && npm run docs:deploy",
        "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
        "test": "umi-test",
        "test:coverage": "umi-test --coverage",
        "prepublishOnly": "npm run build"
      },
      "main": "lib/index.js",
      "module": "es/index.js",
      "typings": "es/index.d.ts",
      "gitHooks": {
        "pre-commit": "lint-staged"
      },
      "lint-staged": {
        "*.{js,jsx,less,md,json}": [
          "prettier --write"
        ],
        "*.ts?(x)": [
          "prettier --parser=typescript --write"
        ]
      },
      "dependencies": {
        "react": "^16.12.0 || ^17.0.0"
      },
      "devDependencies": {
        "@testing-library/jest-dom": "^5.15.1",
        "@testing-library/react": "^12.1.2",
        "@types/jest": "^27.0.3",
        "@umijs/fabric": "^2.8.1",
        "@umijs/test": "^3.0.5",
        "conventional-changelog-conventionalcommits": "^5.0.0",
        "dumi": "^1.1.0",
        "father-build": "^1.17.2",
        "gh-pages": "^3.0.0",
        "lerna": "^4.0.0",
        "lint-staged": "^10.0.7",
        "prettier": "^2.2.1",
        "yorkie": "^2.0.0"
      }
    }
    
    
    • 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
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    根目录lerna.json文件

    {
      "packages": ["packages/*"],
      "version": "independent",
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    子包package.json文件

    {
      "name": "picture-hot-zone",
      "version": "0.4.6",
      "description": "图片热区生成",
      "keywords": [
        "图片热区",
        "低代码",
        "antd",
        "react"
      ],
      "author": "“田迪生” ",
      "homepage": "https://tiandisheng.top/",
      "license": "Apache-2.0",
      "main": "lib/PictureHotZone.js",
      "directories": {
        "lib": "lib",
        "test": "__tests__"
      },
      "files": [
        "lib",
        "es"
      ],
      "repository": {
        "type": "git",
        "url": "git+https://github.com/tianxintiandisheng/tds-components.git"
      },
      "scripts": {
        "test": "echo \"Error: run tests from root\" && exit 1"
      },
      "bugs": {
        "url": "https://github.com/tianxintiandisheng/tds-components/issues"
      },
      "gitHead": "37adb15a032aa074309a15763f63cc8d1ca9fd0d",
      "dependencies": {
        "antd": "^4.22.2",
        "classnames": "^2.3.1",
        "react-rnd": "^10.3.7"
      }
    }
    
    
    • 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
    • 36
    • 37
    • 38
    • 39
    • 40

    项目地址


    解决过程

    1 简单查看,应该是权限问题;

    2. 到对应文件夹下运行‘npm publish’,发布成功;判断不是npm问题,是lerna问题

    3. 搜索‘lerna 401 UNAUTHORIZED’,

    4. 尝npm adduser的方案(参考资料),过程如下,无效

    tiands@tiandsdeMacBook-Pro tds-components % npm adduser
    Username: tianxintiandisheng
    Password: 
    Email: (this IS public) 1455701196@qq.com
    npm notice Please check your email for a one-time password (OTP)
    Enter one-time password from your authenticator app: 61041647
    Logged in as tianxintiandisheng on https://registry.npmjs.org/.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5.尝试修改子包package.json(参考资料)

    before

      "repository": {
        "type": "git",
        "url": "git+https://github.com/tianxintiandisheng/tds-components.git"
      },
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    after

      "repository": {
        "type": "git",
        "url": "git@github.com:tianxintiandisheng/tds-components.git",
        "directory": "packages/PictureHotZone"
      },
      "publishConfig": {
        "registry": "https://npm.pkg.github.com"
      },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    报错

    lerna http fetch PUT 404 https://npm.pkg.github.com/picture-hot-zone 1220ms
    lerna ERR! E404 404 Not Found - PUT https://npm.pkg.github.com/picture-hot-zone
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    
    • 1
    • 2
    • 3
    • 4

    6.我已经放弃用learn进行发包了,打算自己写脚本去子包下面运行npm publish;无意中尝试用lerna publish进行发布,发布成功了;难道是生成日志的影响吗?

    7. 再次修改代码,在命令行终端使用lerna publish --conventional-commits ,发布成功;和生成日志没有关系,难道是不能使用快捷命令?

    8.再次修改代码,在命令行终端使用npm run release-log ,发布成功;和快捷命令没有关系,难道是不能使用yarn?

    9. 仔细观察使用npm和yarn发布时的日志有何不同之处,发现使用yarn release-log时控制台有额外的警告信息,信息如下:

    lerna WARN lifecycle The node binary used for scripts is /var/folders/l0/6dy1snp120d16rm5p01rjh080000gn/T/yarn--1659415304035-0.8034999449885523/node but npm is using /Users/tiands/.nvm/versions/node/v14.18.1/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
    
    • 1

    10. 新建.npmrc文件,并在该文件内添加scripts-prepend-node-path=true;再次修改代码,在命令行终端使用yarn release-log ;报错如下(此时警告的日志没有了):

    lerna http fetch PUT 401 https://registry.npmmirror.com/picture-hot-zone 833ms
    lerna ERR! E401 [UNAUTHORIZED] Login first
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    
    • 1
    • 2
    • 3
    • 4

    11. 毁灭吧,我就用npm run release-log发布好了

    12.在lerna的github上提交了issues,期待中


    环境信息

    info cli using local version of lerna
    lerna notice cli v4.0.0
    lerna info versioning independent
    
     Environment info:
    
      System:
        OS: macOS 12.0.1
        CPU: (8) arm64 Apple M1
      Binaries:
        Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
        Yarn: 1.22.15 - ~/.yarn/bin/yarn
        npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
      Utilities:
        Git: 2.30.1 - /usr/bin/git
      npmPackages:
        lerna: ^4.0.0 => 4.0.0 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
  • 相关阅读:
    Vue框架--Vue中的样式绑定
    使用亚马逊云服务器在 G4 实例上运行 Android 应用程序
    精通Spring Boot单元测试:构建健壮的Java应用
    Cholesterol-PEG-FITC,Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素水溶性
    类和对象:初始化列表,静态成员,友元,内部类,匿名对象
    ES6中导入import导出export
    在线兴趣教学类线上学习APP应用开发部署程序组建研发团队需要准备什么?
    c#和Java我到底该怎么选?
    从零开始搭建搜索推荐系统(五十二)ElasticSearch搜索利器
    vue2 源码解析(四)data数据响应式
  • 原文地址:https://blog.csdn.net/tianxintiandisheng/article/details/126106917