components icon indicating copy to clipboard operation
components copied to clipboard

Does not package with ng-packagr

Open nmrichards opened this issue 9 years ago • 25 comments

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?

  1. Start a new project using cli. ng new material-test
  2. Update dependencies to use @angular/material 2.0.0-beta.12 and all peer dependencies.
  3. Add ng-packagr to dev dependencies, all necessary files for ng-packagr (public_api & ng-package.json) and run npm install.
  4. Import any material module into main app module
  5. run ng-packagr -p ng-package.json.

OR

  1. Checkout https://github.com/nmrichards/material-issue-project
  2. run npm install
  3. 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

screenshot 2017-10-10 07 48 10

nmrichards avatar Oct 10 '17 12:10 nmrichards

I'm not really sure what that is. We maintain our own packaging tooling currently with gulp.

gulp material:build-release

jelbourn avatar Oct 10 '17 13:10 jelbourn

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.

matt328 avatar Oct 10 '17 13:10 matt328

I agree with @matt328 , it is very important for us to be able to use Material in our own component libraries. Something must have changed between beta.11 and beta.12 to break what ng-packagr is trying to accomplish. I am seeing the same issue and looking forward to your insight, @jelbourn

wallace41290 avatar Oct 10 '17 13:10 wallace41290

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.

jelbourn avatar Oct 10 '17 13:10 jelbourn

@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).

screen shot 2017-10-10 at 9 40 09 am

maybe from #7403

We are removing sorcery until we can upgrade tsickle and ngc to latest. Our versions of these break when mapping all the way back to TS. (temporary)

willshowell avatar Oct 10 '17 13:10 willshowell

@willshowell I'll defer any sourcemap stuff to @kara

jelbourn avatar Oct 10 '17 13:10 jelbourn

@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.

matt328 avatar Oct 10 '17 14:10 matt328

Hi @jelbourn,

author of ng-packagr here. It's a tool for (publicApi: TypeScriptFile) => { fesm5, fesm15, umd, ... } compiling/bundling, pretty much like angular-quickstart-lib in a CLI command.

Two observations:

  1. Users need to configure their external dependencies. rxjs and some @angular/* core packaged are pre-configured. @angular/material is not on the list.

  2. On sourcemaps, there had been some issues w/ the ng CLI in the past. It could happen sourcemaps of a library were corrupt and then some of the webpack tools produced build errors. Error was in build of an app depending on a lib; not in library build.

For your concerns, sourcemaps could potentially break a user's build. Someone would need to find a repro.

dherges avatar Oct 10 '17 15:10 dherges

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.

denver-HJS avatar Oct 11 '17 16:10 denver-HJS

@matt328 I spent 2 days on this. This saved some other days I was going to waste. Thank you!

mohyeid avatar Nov 24 '17 19:11 mohyeid

I'm having the same issue with @angular/material and the "externals" fix has not resolved it.

{ "$schema": "./node_modules/ng-packagr/package.schema.json", "ngPackage": { "lib": { "entryFile": "public_api.ts", "externals": { "@angular/material": "ng.material" } } } }

I'm getting:

BUILD ERROR ENOENT: no such file or directory, open '...\node_modules\@angular\packages\material\esm5\core\animation\animation.js.map' Error: ENOENT: no such file or directory, open '...\node_modules\@angular\packages\material\esm5\core\animation\animation.js.map'

drullo avatar Dec 05 '17 20:12 drullo

@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:

{
  "$schema": "./../../node_modules/ng-packagr/ng-package.schema.json",
  "lib": {
    "entryFile": "index.ts",
    "externals": {
      "@angular/material": "ng.material"
    }
  }
}

mohyeid avatar Dec 07 '17 18:12 mohyeid

@drullo Did you try to add each submodule of @angular/material like this :

{
    "$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"
        }
    }
}

Fairen avatar Dec 08 '17 09:12 Fairen

@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.

drullo avatar Dec 08 '17 13:12 drullo

@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 avatar Dec 08 '17 13:12 drullo

@drullo - your method worked for me as well. I had to go back and modify all of my imports to the latest approach. "externals": { "@angular/material/autocomplete": "ng.material.autocomplete", "@angular/material/input": "ng.material.input", "@angular/material/select": "ng.material.select" }

jason-costello avatar Dec 15 '17 21:12 jason-costello

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:

"@angular/material/core/animation": "ng.material.core.animation",

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 avatar Jan 08 '18 22:01 scottmcmaster

@scottmcmaster no, I didn't not have to add an entry for @angular/material/core/animation. Can you post your error and a copy of your ng-package.json?

drullo avatar Jan 09 '18 12:01 drullo

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.

jason-costello avatar Jan 09 '18 14:01 jason-costello

@drullo sure, thanks :).

Here is the packaging output:

`Building Angular library Generating bundle for my-project Cleaning bundle build directory Processing assets Running ngc Compiling to FESM15 'LOCALE_ID' is imported from external module '@angular/core' but never used

BUILD ERROR ENOENT: no such file or directory, open 'G:\myprojectdirectory\node_modules@angular\packages\mater ial\esm5\core\animation\animation.js.map' Error: ENOENT: no such file or directory, open 'G:\myprojectdirectory\node_modules@angular\package s\material\esm5\core\animation\animation.js.map'`

And here is my ng-package.json:

{ "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "entryFile": "public_api.ts", "externals": { "@angular/material": "ng.material", "@angular/material/button": "ng.material.button", "@angular/material/dialog": "ng.material.dialog", "@angular/material/menu": "ng.material.menu", "@angular/material/core/option": "ng.material.core.option", "@angular/material/select": "ng.material.select", "@angular/material/tabs": "ng.material.tabs", "angular-tree-component": "angular-tree-component", "ng-drag-drop": "ng-drag-drop" } } }

scottmcmaster avatar Jan 11 '18 18:01 scottmcmaster