-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not package with ng-packagr #7681
Comments
I'm not really sure what that is. We maintain our own packaging tooling currently with gulp. gulp material:build-release |
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. |
It's impossible for me to say what the issue might be, since this is the first time I've heard of this tool. We unfortunately don't have the capacity to track down issues with 3rd party tools; if someone is able to point to a specific issue with the package output, we can make any necessary changes to the packaging. |
@nmrichards I only have brief experience with ng-packagr, but it looks like you're trying to bundle @jelbourn it does look like there is an invalid sourcemap url (also could be my own ignorance about how they work). maybe from #7403
|
@willshowell I'll defer any sourcemap stuff to @kara |
@willshowell adding material to lib.externals in ng-package.json: {
"lib": {
"entryFile": ...,
"externals": {
"@angular/material": "ng.material"
}
} 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. |
Hi @jelbourn, author of ng-packagr here. It's a tool for Two observations:
For your concerns, sourcemaps could potentially break a user's build. Someone would need to find a repro. |
Just my two cents, but I've found ng-packagr to be a great tool for packaging/publishing reusable components. The suggestion from @matt328 worked for me as well. |
@matt328 I spent 2 days on this. This saved some other days I was going to waste. Thank you! |
I'm having the same issue with @angular/material and the "externals" fix has not resolved it. { I'm getting:
|
@drullo I think you may need to check the relative path of your node_modules file. Also for some reason I do not see ngPackage in my ng-package.json. Here is how this file look like in my end:
|
@drullo Did you try to add each submodule of {
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "public_api.ts",
"externals": {
"@angular/material": "ng.material",
"@angular/material/icon" : "ng.material.icon",
"@angular/material/toolbar" : "ng.material.toolbar"
}
}
} |
@mohyeid, you're right that "ngPackage" didn't belong in the ng-package.json file. Originally, I had my configuration placed into the package.json file - which does require it to be in the "ngPackage" section. When I transitioned my configuration from package.json to ng-package.json, I forgot to remove the "ngPackage" wrapper initially. |
@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. |
@drullo - your method worked for me as well. I had to go back and modify all of my imports to the latest approach. |
I'm still having this issue with my particular build. @drullo @jrc60752 I figure you are using Material modules that rely on anomations, did you also have to add an "externals" entry along the lines of:
For the specific animation.js.map error? In spite of the fact that nobody (I suspect) actually imports that directly in TS code. That said, when I try this, it doesn't seem to help... |
@scottmcmaster no, I didn't not have to add an entry for |
I had to go back and refresh my memory...a few weeks off and I forgot what this was referring to. my complete ng-package.json file contains: {
"lib": {
"entryFile": "public_api.ts",
"externals": {
"@angular/material/autocomplete": "ng.material.autocomplete",
"@angular/material/input": "ng.material.input",
"@angular/material/select": "ng.material.select"
}
}
} and public_api.ts contains (names are a bit odd as I had to change a view names to remove company info): export * from './src/app/modules/my-custom-selector/my-custom-selector.module'; my-custom-selector.module contains: import { NgModule } from '@angular/core';
import { BrowserModule } from "@angular/platform-browser";
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import {MyCustomSelectorComponent} from './my-custom-selector.component';
import {MyCustomPersonnelFinderService} from './my-custom-personnel-finder.component';
import {MatAutocompleteModule} from '@angular/material/autocomplete';
import {MatInputModule} from '@angular/material/input';
import {MatSelectModule} from '@angular/material/select';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
CommonModule,
MatAutocompleteModule,
MatInputModule,
MatSelectModule,
BrowserAnimationsModule,
],
declarations: [MyCustomSelectorComponent],
providers: [MyCustomPersonnelFinderService],
exports: [MyCustomeSelectorComponent]
})
export class MyCustomSelectorModule {} With the above, I was able to package everything up with no issues and import into a co-workers application as a test. |
@drullo sure, thanks :). Here is the packaging output: `Building Angular library BUILD ERROR And here is my ng-package.json:
|
Update: I revved some components just for the heck of it, and now it packages ok. Here is the diff. Doesn't seem like it should be too significant, but in case this helps somebody:
|
What is the preferred way to use @angular/material in your library project? Is the process defined? |
When using ng-packagr to package a component with @angular/material I recieve a build error : mat-toolbar not found ( sale message for all other material tag mat-icon, mat-xxx) |
@matt328 your suggestion below don’t work for me. You confirm that it need just to add externals libs ? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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?
ng new material-test
npm install
.ng-packagr -p ng-package.json
.OR
npm install
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
The text was updated successfully, but these errors were encountered: