问题描述
运行命令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.
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"
}
}
根目录lerna.json
文件
{
"packages": ["packages/*"],
"version": "independent",
}
子包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. 到对应文件夹下运行‘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/.
5.尝试修改子包package.json(参考资料)
before
"repository": {
"type": "git",
"url": "git+https://github.com/tianxintiandisheng/tds-components.git"
},
after
"repository": {
"type": "git",
"url": "git@github.com:tianxintiandisheng/tds-components.git",
"directory": "packages/PictureHotZone"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
报错
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.
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.
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.
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