Building a library with dependent libraries defined via paths
See original GitHub issueType of Issue
[ x] Bug Report
[ ] Feature Request
Description
I have a project with monorepo structure. In general, it somethink like this
-apps -projects –lib1 –lib2 –lib3
And these libs has configured paths in tsconfig: @project/lib1 - projects/lib1, etc…
And libs can use other libs, for example lib1 can be used in lib2 and lib2 can be used in lib3 via path.
When I trying a build lib which depends on other lib (in example case lib1) via ng build --project=lib1 ng-packagr builds a strange dist directory structure. There is an example of ng-package.json of first lib.
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/lib1",
"deleteDestPath": false,
"workingDirectory": ".",
"lib": {
"entryFile": "index.ts",
}
}
and in this case resulting sturcture in dist folder will be like this:
-libs
-lib1
|
|----esm5
| |----lib1
| |----lib2
| └----lib3
|----esm2015
| |----lib1
| |----lib2
| └----lib3
|----lib1
|----lib2
└----lib3
and ng-packagr calls rollup for dist/libs/lib1/ems2015/project-lib1.js, which calls an error, because this file is not exists.
Could not resolve entry (~/Documents/project/dist/libs/lib1/esm2015/project-lib1.js)
Error: Could not resolve entry (~/Documents/project/dist/libs/lib1/esm2015/project-lib1.js)
at error (~/Documents/project/node_modules/rollup/dist/rollup.js:3766:30)
at ~/Documents/project/node_modules/rollup/dist/rollup.js:18207:17
Is there a bug, or it is a configuration issue?
Do you have workaround for it?
How To Reproduce
Build project sturcture like described and call ng buld for project with dependencies.
Expected Behaviour
Successful build or my-code-related error.
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 5.0.1
@angular/*: 7.2.4
typescript: 3.1.5
rxjs: 7.2.0
node: v11.5.0
npm: 6.4.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:37 (6 by maintainers)
Top GitHub Comments
I’ve also run into this problem and I have found a solution that appears to work (it lets me build my library at least) but I thought I’d share it and maybe someone can tell me if it would cause problems that I don’t see.
It seems too simple given all the discussion I’ve seen of this problem, so I’m assuming it’s already been discounted.
We have an Angular component library with multiple entry points so:
old setup
component2/package.json:
component2/public_api.ts:
This was working fine but when I tried to have
component2
importcomponent1
I ran into therootDir
error becausecomponent1
was not found in thecomponent2
directory.I have moved the component entry points up one level into the lib directory but leaving the package.json in the component directory.
This appears to cause
rootDir
to be set as thelib
directory instead of the component directory and allow my library to build successfully.new setup
component2/package.json:
component2-public_api.ts:
I hope that makes sense and I’d be really grateful if someone has some input on whether it’s a valid solution. Apologies for hijacking the thread but it seems relevant to the discussion.
I’m facing the same issue as @qballer . I have an angular monorepo with a number of libraries in it. These libraries import from each other based on paths defined in the root tsconfig.json file:
The auth lib for example makes use of @x/helpers and @x/api