angular: bug(compiler-cli): metadata resolution error when generating flat module with reference in re-export
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
GIVEN
There is a HelloComponent
in app/components/hello.component
.
There is a re-export of HelloComponent
in app/components.ts
, like:
export * from './components/hello.component'
In app.module.ts
, import HelloComponent
from app/components.ts
(re-export), like:
// ...
import { HelloComponent } from './components'
@NgModule({
declarations: [
// ...
HelloComponent,
],
// ...
})
export class AppModule { }
Checked not relates to filename.
WHEN
Config it to generate a flat module:
{
"angularCompilerOptions": {
"flatModuleId": "hello",
"flatModuleOutFile": "hello.js",
"skipTemplateCodegen": true
}
}
And call AOT compiler via ngc
.
THEN
An error occur:
MACHINE_NAME:aot-reexport-issue zjyu$ $(yarn bin)/ngc -p src/tsconfig.app.json
: TypeError: Cannot read property 'module' of undefined
at MetadataBundler.convertSymbol (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:264:57)
at createReference (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:390:23)
at MetadataBundler.convertReference (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:438:24)
at MetadataBundler.convertExpression (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:367:33)
at MetadataBundler.convertValue (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:348:25)
at /Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:58
at Array.map (<anonymous>)
at MetadataBundler.convertValue (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:26)
at MetadataBundler.convertValue (/Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:357:32)
at /Users/USER_NAME/Projects/github/trotyl/aot-reexport-issue/node_modules/@angular/compiler-cli/src/metadata/bundler.js:351:58
The error is caused by this line, canonicalSymbol
doesn’t have a declaration
property in this scenario.
Expected behavior
Be able to compile.
Minimal reproduction of the problem with instructions
https://github.com/trotyl/aot-reexport-issue
Steps mentioned there.
What is the motivation / use case for changing the behavior?
Be able to get codes work.
Environment
Angular version: 5.1.0
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 8.9.2
- Platform: Mac
Others:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 39
- Comments: 22 (9 by maintainers)
Commits related to this issue
- feat(admin-ui): Update Angular to v9 Note that AOT is explicitly turned off in angular.json for plugin compilation. This is due to a bug in the ng compiler dealing with barrel files (i.e. the index.t... — committed to vendure-ecommerce/vendure by michaelbromley 4 years ago
- fix(cart): fix cart paths to use public_api When doing AOT compilation, things like barrel exports and paths like 'path/to/dir' where you're actually referring 'path/to/dir/index' can make some wild ... — committed to graycoreio/daffodil by damienwebdev 4 years ago
- fix(cart): fix paths to use public_api instead of index (#709) When doing AOT compilation, things like barrel exports and paths like 'path/to/dir' where you're actually referring 'path/to/dir/index' ... — committed to graycoreio/daffodil by damienwebdev 4 years ago
- 💚 Fix imports for ngc compilation... See: https://github.com/ng-packagr/ng-packagr/issues/1173 https://github.com/angular/angular/issues/20931 — committed to kirbydesign/designsystem by jakobe 4 years ago
- Ui/modal (#988) * ⬆ Bump typescript * ⬆ Bump Angular to 9 * ⬆ Bump devDependencies * ⬆ Bump ng-mocks * 📦 Fix package exports * ⬆ Bump ng-packagr * :wrench: Add ngcc postinstall scr... — committed to kirbydesign/designsystem by jakobe 4 years ago
- Enable Ivy to fix "Cannot read property 'module' of undefined" error when building with --prod Related to https://github.com/angular/angular/issues/20931 — committed to RonasIT/angular-common by dmitryusenko 4 years ago
Any updates?
Any update here?
Importing it from where it is defined is work for me.
It is a problem for me as well, with
@angular/cli
7.2.6 &@angular/cli
7.3.3. Is there any plan to fix this?I noticed unexpected (for me) behavior:
In this case i got error
TypeError: Cannot read property 'module' of undefined
. But if edit export string in barrel file toexport * from './body.interface';
build error will disappearIs there any workaround ?
The issue https://github.com/ng-packagr/ng-packagr/issues/1173#issuecomment-551577679 referred me to this issue.
This issue prevents my library to use secondary-entry points and would save a lot of package size because of non-tree-shakable third-party libs. Neither is Ivy a thing for library-authors yet nor is there a workaround for this issue (at least I could not get it working)
How can this be a
very low priority
issue?If this is not related to this issue I can open a new issue instead.
Addition to this issue
I tried to create two secondary entry points. One does work, one does not and I can’t see a difference.
This does work
ui/charts/package.json
public_api.ts
This does not work
ui/object-editor/package.json
public_api.ts
Error message
Further information
Conclusion
The only difference I spot is the dependencies of both entry points. I’d be happy to help with further information if you need them.
Instead of
index.ts
files,we’re using private Angular Modules
This helps in a few cases to reduce direct referencing.
But
index.ts
files would be much better!!!Any ETA on this ? Resolving from index barrel is kind of important on large, multi-teams project…
For Angular Library make sure your index barrel are exported in your library main index barrel (aka public_api)
I was getting this error in my angular library when I imported like:
But this workaround fixed it for me:
Marking as fixed by Ivy but still an issue today, as libraries are still built for VE therefor dependent on the metedata bundler.
We are running into this issue as well (ng-packagr uses this approach rendering the solution useless). Just with a single SharedModule that is reexported through an index file. It breaks. The error is thrown on line 344 of the bundler.ts file
const module = this.getMetadata(declaration.module);
. declaration is undefined. The declaration is found on the symbol just not on the canonicalSymbol.