question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Having a problem when creating package with RouterModule imported in NgModule decorator

See original GitHub issue

Type of Issue

[x ] Bug Report
[ ] Feature Request

Description

I’m unable to create a package using ng-packagr@v3.0.0-rc.0. Also I’m using the latest angular version .There is a build error i get when I run the packagr. This only happens when I import the RouterModule inside the imports section of the @NgModule decorator. Like so:

@NgModule({ declarations: [ AppComponent ], imports: [ CommonModule, RouterModule.forChild(routes) ], // providers: [ // { // provide: ROUTES, // useValue: routes, // multi: true // }, // { // provide: ANALYZE_FOR_ENTRY_COMPONENTS, // useValue: routes, // provide them here too // multi: true // } // ], }) export class AppModule { }

The error i get is : BUILD ERROR Error during template compile of ‘AppModule’ Function calls are not supported in decorators but ‘RouterModule’ was called.

However, if i add it to through the providers section(commented out), then there is no error and the package is successfully _created.

How To Reproduce

I’ve created a repository containing the full app. Just download, npm install and then run npm run packagr, in order to reproduce the issue. The link to the repo : https://github.com/SoundarDinesh/lib-using-ng-packagr.git

_

Expected Behaviour

The package should be created when adding RouterModule.forChild in the imports section.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 3.0.0-rc.0
@angular/*: 6.0.0-rc.5
typescript: ~2.7.2
rxjs: 6.0.0-rc.0
node: v8.11.1

Please include all version numbers that might be relevant, e.g. third-party libraries

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

38reactions
rhalffcommented, Apr 28, 2018

Update:

The correct solution seems to be:

export const routerModuleForChild = RouterModule.forChild(routes)

@NgModule({
  imports: [
    routerModuleForChild
  ],
  ...
})

See: https://github.com/ngxs/store/blob/master/packages/router-plugin/src/router.module.ts

1reaction
dhergescommented, Apr 28, 2018

Note: skipTemplateCodegen: "false"|"true" impacts the above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NgModule FAQ - Angular
This page answers the questions many developers ask about NgModule design and ... Import FormsModule from @angular/forms if your components have [(ngModel)] ...
Read more >
Angular Modules and NgModule - Complete Guide
This happens by design: Modules that are directly imported are usually meant to enrich the importing module functionality (in this case, the ...
Read more >
Appears in the NgModule.imports of AppModule, but could not ...
I forgot to append 'Module' suffix to the import and export declaration. The following fixed the problem: import { MatListModule } from "@ ......
Read more >
Angular 12 Routing By Example - webtutpro
We import the Routes and RouterModule symbols from the @angular/router package which is the central repository that holds all the Router ...
Read more >
Avoiding common confusions with modules in Angular
Angular creates a lazy-loaded module with its own injector, a child of the root injector… So a lazy-loaded module that imports that shared...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found