Using Lerna with unpublished packages
我正在尝试与Lerna建立我的monorepo。 计划是通过提取应属于自己的程序包的代码块来重构现有项目。 我已经运行了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | project/ packages/ new-refactored-package/ package.json prior-existing-project/ package.json {"dependencies" : {"new-refactored-package" :"latest" } } package.json { "devDependencies": { "lerna":"^2.0.0-rc.5" } } lerna.json { "lerna":"2.0.0-rc.5", "packages": [ "packages/*" ], "version":"0.0.0" } |
我的理解是,此时应该
Bootstrap the packages in the current Lerna repo. Installs all of their dependencies and links any cross-dependencies.
When run, this command will:
- npm install all external dependencies of each package.
- Symlink together all Lerna packages that are dependencies of each other.
- npm prepublish all bootstrapped packages.
但是,当我运行它时,lerna尝试改为
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/new-refactored-package
我误会了吗 我是否首先必须将依赖软件包发布到
要求
为了使
因此,请确保依赖项包的版本可以与依赖项中的semver版本匹配。
例
1 2 3 4 5 | { name:"@my-name/dependency", version:"1.2.0" } |
1 2 3 4 5 6 | { name:"@my-name/dependant", dependencies: { "@my-name/dependency":"<VERSION>" } } |
当
在问题中说明的实际情况中,实际问题是版本指定为
如果查看诸如
您未发布的程序包没有任何标签,因为它们已应用于发布,因此
在
- When a dependency version in a package is not satisfied by a package of the same name in the repo, it will be
npm install ed (oryarn ed) like normal.- Dist-tags, like
latest , do not satisfy semver ranges.- Circular dependencies result in circular symlinks which may impact your editor/IDE.
解
如果要匹配可用的任何版本,建议的路径是将版本设置为
1 2 3 4 5 | { "dependencies": { "new-refactored-package" :"*" } } |
alpha ,rc orbeta Even
* will not match versions that are marked as pre-release, so if you give your local package a version like0.0.1-alpha.0 , or1.0.0-rc.3 , it will also not be locally symlinked
尽管它不影响
如果可用,
在您的情况下,我认为lerna无法找到软件包的正确
这是我在项目中所做的...
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 | project - packages/ - a_pkg - package.json { "name":"@scope/a_pkg", "version":"0.0.1", "private": true /// opt out } - b_pkg - package.json { "name":"@scope/b_pkg", "version":"0.0.1", "private": true, "dependencies": { "@scope/a_pkg":"^0" }, /// opt out } - package.json - lerna.json { "packages": [ "packages/*" ], /// opt out } |
由于您尚未发布您的作品,因此我将尝试在
package.json中的软件包名称必须与/ packages文件夹中的文件夹名称匹配。
(基本上是@kp_ping所说的)