components: Does not package with ng-packagr
Bug, feature request, or proposal:
When using ng-packagr, I receive a build error "ENOENT: no such file or directory, open ‘…/node_modules/@angular/packages/material…’
What is the expected behavior?
It packages properly with no build errors.
What is the current behavior?
It errors out and doesn’t build successfully but I can do ng build without issues.
What are the steps to reproduce?
- Start a new project using cli.
ng new material-test
- Update dependencies to use @angular/material 2.0.0-beta.12 and all peer dependencies.
- Add ng-packagr to dev dependencies, all necessary files for ng-packagr (public_api & ng-package.json) and run
npm install
. - Import any material module into main app module
- run
ng-packagr -p ng-package.json
.
OR
- Checkout https://github.com/nmrichards/material-issue-project
- run
npm install
- run
npm run packagr
What is the use-case or motivation for changing an existing behavior?
To be able to use ng-packagr with beta.12 in personal libraries.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
@angular 4.4.4 Material 2.0.0-beta.12 TypeScript 2.3.3
Is there anything else we should know?
I also receive messages during the ng-packagr process stating a number of items are imported but never used even if I only import one module from material library. See file below for said messages. In this particular test project, I’m only importing MatIconModule into the main app module. If I run ng-packagr on beta.11, I don’t receive the build error but still get the imported but not used messages and it successfully builds. I will also be submitting this to the ng-packagr project as I’m not sure if this an ng-packagr issue or material beta.12 issue but I only get the issue if I import any module from material beta.12. And also putting on Stack Overflow in case it’s just an issue that I’m causing due to something I’m doing wrong, in which case I apologize for submitting this issue.
EDIT: ng-packagr issue can be tracked here #172
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 25 (4 by maintainers)
@willshowell adding material to lib.externals in ng-package.json:
seems to have fixed my issue, my library is now building successfully with ng-packagr.
That is not to say there still isn’t some issue here with the esm5 packaging’s sourcemaps. I think someone consuming the esm5 package would likely face the same errors.
I don’t think this should have been closed. Some clarification: we aren’t trying to use ng-packagr to build material itself. We are working on library projects that include material, and using ng-packagr to build those. The problem seems isolated to the esm5 packaging of material, which I am guessing not many people are using or else this issue would have much more traffic.
Is there a working example of a project successfully using beta.12’s esm5 packaging anywhere?
Edit: I have another project that is using a custom rollup configuration only building umd and fesm modules successfully with material beta.12, so I really think its an issue specific to the esm5 packaging.
@Fairen, that was not the problem initially. However, I did change the way that I’m importing Material modules in my code. Originally, I was importing them all from @angular/material (as this was the way that the material.angular.io documentation instructed users until very recently). But their documentation has changed and I have since learned that that approach (importing modules from “parent” modules that re-export them) is bad for tree shaking and inefficient for AOT. So I have updated my code to import the Material modules individually and yes - after that I did have to add each submodule to the “externals” section of ng-package.json individually.
Incidentally, I also had to add angular2-jwt, in case anybody else is using it.
What is the preferred way to use @angular/material in your library project? Is the process defined?
@nmrichards I only have brief experience with ng-packagr, but it looks like you’re trying to bundle
@angular/material
with your component library. Does it work with setting it as a peer dependency instead? It appears that@angular/cdk/*
are listed as externals by default, but@angular/material
should be added as one in order to not bundle it with your lib.@jelbourn it does look like there is an invalid sourcemap url (also could be my own ignorance about how they work).
maybe from #7403