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.

AOT: Unexpected value 'undefined' exported by the module when using barrel index.ts

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

I’m trying to migrate an existing library to the new Angular-cli library support This library has a lot of barrels index.ts files I’m experiencing error on build with AOT enabled

How To Reproduce

https://github.com/kepennar/ng-cli-lib-issue-repro

Given a library managed by the new angular-cli v6 library management system.

Given a component Comp1Component of this lib imported from a barrel index.ts in a module LibModule

projects/lib1/src/lib/components/index.ts

export * from './comp1.component';

projects/lib1/src/lib/lib.module.ts

import { Comp1Component } from './components';
// ...

@NgModule({
  declarations: [Comp1Component],
  exports: [Comp1Component]
})
export class LibModule {}

When an application using this lib is launched in prod mode

Then build crash with the error

ERROR in : Unexpected value 'undefined' exported by the module 'Lib1Module ...

If the component is directly imported from it’s own file. It’s work

projects/lib1/src/lib/lib.module.ts

import { Comp1Component } from './components/comp1.component';
@NgModule({
  declarations: [Comp1Component],
  exports: [Comp1Component]
})
export class LibModule {}
Reproduction steps

From the repo https://github.com/kepennar/ng-cli-lib-issue-repro

npm run build:lib npm run start:prod

Expected Behaviour

I would like ng-packagr to support correctly barrels files

Version Information

Output from: ng --version.

Angular CLI: 6.0.7
Node: 10.3.0
OS: linux x64
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.6.7
@angular-devkit/build-angular      0.6.7
@angular-devkit/build-ng-packagr   0.6.7
@angular-devkit/build-optimizer    0.6.7
@angular-devkit/core               0.6.7
@angular-devkit/schematics         0.6.7
@angular/cli                       6.0.7
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.7
@schematics/angular                0.6.7
@schematics/update                 0.6.7
ng-packagr                         3.0.0
rxjs                               6.2.0
typescript                         2.7.2
webpack                            4.8.3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:34
  • Comments:31 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
kepennarcommented, Jun 2, 2018

When I change import to

import { Comp1Component } from './components/index';

I have this error during lib build:

BUILD ERROR
Cannot read property 'module' of undefined
TypeError: Cannot read property 'module' of undefined
    at MetadataBundler.convertSymbol (.../node_modules/@angular/compiler-cli/src/metadata/bundler.js:312:61)
4reactions
ytiliscommented, Sep 9, 2019

@blemaire @deepthan Yes, we know. It literally says that direct imports work in the original ticket description:

If the component is directly imported from it’s own file. It’s work

The bug is that barrel imports (index.ts) don’t work, but they should.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Unexpected value 'undefined' imported by the module
I had this error because I had an index.ts file in the root of my app that was exporting my app.component.ts . So...
Read more >
Eror: Unexpected Value 'Undefined' Exported By The Module ...
When I try to compile in AOT or --prod, the build fails with. ERROR in Unexpected value 'undefined' exported by the module 'TreeDiagramModule...
Read more >
Angular and AOT - CODE Magazine
Uncaught Error : Unexpected value 'undefined' imported by module . The solution to this is very straightforward. Simply spell out everything you ...
Read more >
angular/angular-cli - Gitter
Hi guys, someone using barrel imports with new Angular 6 ? ... Unexpected value 'undefined' exported by the module 'ReviewsModule'.
Read more >
Angular Component library: The Definitive Guide - Medium
With AOT, the browser downloads a pre-compiled version of the ... Error: Unexpected value 'undefined' imported by the module 'AppModule' ...
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