ng-packagr: [AoT] [ngc] Re-exports causing build error during
Type of Issue
Getting
[ x] Bug Report
[ ] Feature Request
Description
BUILD ERROR
Cannot read property 'module' of undefined
TypeError: Cannot read property 'module' of undefined
at MetadataBundler.convertSymbol (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:264:57)
at createReference (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:390:23)
at MetadataBundler.convertReference (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:438:24)
at MetadataBundler.convertExpression (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:367:33)
at MetadataBundler.convertValue (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:348:25)
at <..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:58
at Array.map (<anonymous>)
at MetadataBundler.convertValue (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:26)
at MetadataBundler.convertValue (<..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:357:32)
at <..>/ng-packaged/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:58
The error occurs when I import the shared module from the index.ts file. i.e. import { SharedModule } from "./shared/index". If I import directly from the shared.module the error goes away. I’ve never had a problem using index files before and would like to know more about why it’s failing.
index.ts
export * from "./shared.module";
shared.module.ts
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
@NgModule({
imports: [
CommonModule
],
declarations: [
],
exports: [
]
})
export class SharedModule {}
How To Reproduce
Expected Behaviour
I can import reexports properly without getting cryptic error.
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 2.0.0-rc.10
@angular/compiler: 5.2.0
@angular/compiler-cli: 5.2.0
rollup: 0.53.0
tsickle: 0.26.0
typescript: 2.6.2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 20 (3 by maintainers)
Any news?
In Angular, the error occurs when importing stuff from barrels in a module or routing file. As many people said in above comments, the error disappears when one imports the component/service from the actual file path and not from the barrel. Versions: “ng-packagr”: “^4.1.0” “@angular/cli”: “^6.2.7” “@angular/xxx”: “^6.1.10” “typescript”: “^2.9.2”.
It would be really wonderful if at least the error message was a bit more descriptive because this minor issue can make people waste a lot of time.
This frequently affects me when working on a large project and I spend way too much time finding out what export is missing. The error message is useless.
I did get a similar issue due to Typescript Barrels.
My secondary entry point uses a barrel but didn’t export all the component which were imported elsewhere this lead to the creation of an extra file with this forgotten to export component:
As multiple of my libraries had the same issue it complained about re-exporting the same symbol.
I could resolve the issue by exporting the
MatOverlayOriginComponentin theindex.tsof its module.Hope this can help in resolving this issue
@siderite you have to export all components, modules and pipes out of the index file that ng packagr uses. That means that you can’t have any private modules used only internally. They have to all be exported towards the top level
I got the same issue in my project. We defined the following rule for our development “Export from barrels, but only explicitly import from single files instead of barrels”.
Is there a solution on your side to fix this in an upcoming version? It would make our code more lean if imports from barrels are possible (e.g. in routing-modules defining routes and navigation structure)
Not a v1 issue. issue reproducible in v2 with angular 5.
By applying this change set, the compile error goes away.
On first sight, it looks related to TypeScript barrels (#195). But, the import was explicit to the
./shared/index(not the folder name which will be aliased to index).Here are the bundle indexes:
$ cat my-lib.d.ts
$ cat my-lib.metadata.json