amplify-js: After upgrade to Angular 9 get error "ERROR in Cannot read property 'length' of undefined" when building aws-amplify-angular
Describe the bug The application used aws-amplify and aws-amplify-angular. It was building as expected when on angular version 8 but after upgrade to angular version 9 the build process throws up the following error:

Tried uninstalling and installing the npm packages to makes sure its on latest but this didn’t fix the issue.
It seems to be building the module as esm5 even though the target in tsconfig is set to es2015 which might be related but thats just a case.
Thanks in advance 😃
Update I created a new angular 9 project and installed aws-amplify-angular and it built without error. The tsconfig.json was a little different so I copied it from the new project into my application but it didn’t fix the error.
To Reproduce
package.json
{
"name": "",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --port 4200 --ssl",
"buildprod": "ng build --prod --configuration=production",
"buildstaging": "ng build --prod --configuration=staging",
"builddev": "ng build --prod --configuration=devdeploy",
"stats": "ng build --stats-json",
"analyze": "webpack-bundle-analyzer dist/stats.json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "~0.900.0-rc.7",
"@angular/animations": "^9.0.0-rc.7",
"@angular/cdk": "^9.0.0-rc.6",
"@angular/common": "9.0.0-rc.7",
"@angular/compiler": "9.0.0-rc.7",
"@angular/core": "9.0.0-rc.7",
"@angular/forms": "9.0.0-rc.7",
"@angular/http": "7.2.15",
"@angular/material": "^9.0.0-rc.6",
"@angular/platform-browser": "9.0.0-rc.7",
"@angular/platform-browser-dynamic": "9.0.0-rc.7",
"@angular/router": "9.0.0-rc.7",
"@aws-amplify/auth": "^2.1.2",
"@aws-amplify/core": "^2.2.1",
"@egjs/hammerjs": "^2.0.17",
"@types/vis": "^4.21.19",
"angular-file-uploader": "^5.0.2",
"angular-webstorage-service": "^1.0.2",
"aws-amplify-angular": "^4.1.2",
"core-js": "^3.6.2",
"jquery": "^3.4.1",
"keycharm": "^0.3.1",
"ngx-color-picker": "^8.2.0",
"popper.js": "^1.16.0",
"rxjs": "^6.5.4",
"tslib": "^1.10.0",
"vis-data": "^6.3.1",
"vis-network": "^6.5.0",
"vis-util": "^2.0.2",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular/cli": "^9.0.0-rc.7",
"@angular/compiler-cli": "9.0.0-rc.7",
"@angular/language-service": "9.0.0-rc.7",
"@types/jasmine": "^3.5.0",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~3.0.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.5.1",
"protractor": "^5.4.2",
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.6.4",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.10"
},
"description": "sadf",
"main": "index.js"
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"types": ["node"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": ["node_modules/@types"],
"lib": ["es2017", "dom"],
"module": "esnext",
"baseUrl": "./",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
Environment
VS Code Angular CLI: 9.0.0-rc.7 Node: 10.16.3 OS: win32 x64 Angular: 9.0.0-rc.7 ... animations, cli, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... router Ivy Workspace: YesAbout this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 78 (14 by maintainers)
Commits related to this issue
- fix(aws-ampilify-angular: (#4681) Fix dynamic rendering to support angular 9 in ivy: false settings — committed to wickstargazer/amplify-js by deleted user 4 years ago
we are f*cked guys lol let’s wait for angular 10
I’m having the same issue. Disabling Ivy does get the build to succeed but i still can’t get the <amplify-authenticator></amplify-authenticator> ui component to work.
Throws the following in the browser: auth.component.html:1 ERROR TypeError: Cannot read property ‘viewContainerRef’ of undefined at AuthenticatorComponent.push…/node_modules/aws-amplify-angular/dist/src/components/authenticator/authenticator/authenticator.factory.js.AuthenticatorComponent.loadComponent (authenticator.factory.js:43) at AuthenticatorComponent.push…/node_modules/aws-amplify-angular/dist/src/components/authenticator/authenticator/authenticator.factory.js.AuthenticatorComponent.ngOnInit (authenticator.factory.js:27) at checkAndUpdateDirectiveInline (core.js:32822) at checkAndUpdateNodeInline (core.js:45557) at checkAndUpdateNode (core.js:45496) at debugCheckAndUpdateNode (core.js:46519) at debugCheckDirectivesFn (core.js:46462) at Object.updateDirectives (auth.component.html:1) at Object.debugUpdateDirectives [as updateDirectives] (core.js:46450) at checkAndUpdateView (core.js:45461)
Thanks everyone for your tenacity & research on this! We’re actively working on Angular 9 (Ivy) support, so your help in “unblocking” development is incredibly helpful and welcomed. 🙏
@LosD Good catch! If that’s the case, someone should submit a ticket on the Angular repository.
EDIT 1 Nevermind, someone already submitted a issue and there is a PR waiting to get reviewed regarding this. error NG1010: Expected array when reading the NgModule.declarations of ExtendedModule
EDIT 2 To test the fix before getting merge, please replace the following devDependency on your package.json file:
It does fix the issue!
Upgraded to angular 9, opting out of Ivy works for me, but would love to see Ivy support soon!
We’re getting some underlying changes out the door, then we’ll get back to checking out the latest v9 stuff, thanks to #4883!
Hey guys, thankz for the response, i opened a PR for this and waiting for them to officially
For now, anyone has a hurry or urgent need like us, please use the ‘@flowaccount/awns-amplify-angular’ 😃
Regards, Wick
Ok guys, Thankz a ton for the heads up on
@angular/compiler-cli… That has gotten me to the right path.Also to be able to get pass the
ngccerror i had to addimportHelpers:truein the tsconfig.json file.However I was still getting the
ViewContainerReferror. It seems like the container is undefined when trying to load the dynamic view!So I have gone through some digging and found out that the error
is coming from the
DynamicComponentDirectivewhile its being loaded inside several classes which uses it to render theIonicandCoreparts differentlyHence i am doing a pull request for this issue right now, and i think it will solve the issue of dynamic view not written to support Angular 9.
However, The correct implmentation for IVY still needs to be done. This is being done under the following
tsconfig.jsonsettings!Baby Steps Right? 👶 🍼
Just found out the issue regarding
aws-amplify-angular:The library does use the spread syntax (operator
...) on ngModule declarations like as amplify-ionic-module.ts, but looks like the new Angular version broke it.There is a Angular issue about that, in this case: ngcc: libraries using spread operator in object literals cannot be processed.
Experiencing the same issue here after upgrading to Angular 9 ! I disabled the IVY compiler to successfully build !
in tsconfig.app.json :
"angularCompilerOptions": { "enableIvy": false }still having look alike problem using the package from build artifacts !!!
@KingDarBoja I was able to get past all errors and build successfully. Here are the steps I took…
“@angular/compiler-cli”: “https://621158-24195339-gh.circle-artifacts.com/0/angular/compiler-cli-pr35191-b93c5372e9.tgz”,
this did get past the error but got the error I posted above.
“angularCompilerOptions”: { “enableIvy”: false }
The only catch I see right now is not having authStateChange$ which is the only thing I use from the angular library to know when a user is logged in or out. I’m going to research this more because it may be a deal breaker for now.
After this Amplify is running in Angular 9. Here are by dependencies…
“dependencies”: { “@angular/animations”: “^9.0.2”, “@angular/cdk”: “^9.0.1”, “@angular/common”: “^9.0.2”, “@angular/compiler”: “^9.0.2”, “@angular/core”: “^9.0.2”, “@angular/forms”: “^9.0.2”, “@angular/material”: “^9.0.1”, “@angular/platform-browser”: “^9.0.2”, “@angular/platform-browser-dynamic”: “^9.0.2”, “@angular/platform-server”: “^9.0.2”, “@angular/router”: “^9.0.2”, “@nguniversal/express-engine”: “^9.0.0”, “aws-amplify”: “^2.2.5”, “aws-amplify-angular”: “^4.1.6”, “express”: “^4.15.2”, “guid-typescript”: “^1.0.9”, “moment”: “^2.24.0”, “rxjs”: “~6.5.4”, “rxjs-compat”: “^6.5.4”, “tslib”: “^1.10.0”, “zone.js”: “~0.10.2” }, “devDependencies”: { “@angular-devkit/build-angular”: “^0.900.3”, “@angular/cli”: “^9.0.3”, “@angular/compiler-cli”: “^9.0.2”, “@angular/language-service”: “^9.0.2”, “@nguniversal/builders”: “^9.0.0”, “@types/express”: “^4.17.0”, “@types/jasmine”: “~3.5.0”, “@types/jasminewd2”: “~2.0.3”, “@types/node”: “^12.12.28”, “codelyzer”: “^5.1.2”, “jasmine-core”: “~3.5.0”, “jasmine-spec-reporter”: “~4.2.1”, “karma”: “~4.3.0”, “karma-chrome-launcher”: “~3.1.0”, “karma-coverage-istanbul-reporter”: “~2.1.0”, “karma-jasmine”: “~2.0.1”, “karma-jasmine-html-reporter”: “^1.4.2”, “protractor”: “~5.4.3”, “ts-node”: “~8.3.0”, “tslint”: “~5.18.0”, “typescript”: “~3.7.5” }
ng version…
@angular-devkit/architect 0.900.2 @angular-devkit/build-angular 0.900.3 @angular-devkit/build-optimizer 0.900.3 @angular-devkit/build-webpack 0.900.3 @angular-devkit/core 9.0.2 @angular-devkit/schematics 9.0.3 @angular/cdk 9.0.1 @angular/cli 9.0.3 @angular/material 9.0.1 @ngtools/webpack 9.0.3 @nguniversal/builders 9.0.0 @nguniversal/common 9.0.0 @nguniversal/express-engine 9.0.0 @schematics/angular 9.0.3 @schematics/update 0.900.3 rxjs 6.5.4 typescript 3.7.5 webpack 4.41.2
Another note…I used localStorage in my app init and got an error when browsing to the page.
“ERROR { ReferenceError: localStorage is not defined at AppComponent.ngOnInit”
I removed it and all worked so if you are using ssr you may run into ReferenceErrors like this. I’m new to it and just trying to work through things.
I hope I didn’t miss any steps. I spent hours on this yesterday just trying different things and this thread helped a lot, but I couldn’t find the right combination…it is very frustrating. I may end up rolling back until this is fixed.
Hi guys, i have published
@flowaccoun/aws-amplify-angularversion4.2.11@flowaccount/aws-amplify-angular
Its working with angular 9 now, the issue with the PR here is the auto-build isn’t working because of
yarn versionand I changed the way its packaged, so it will take time for them to publishWe need to use it now, so I took the liberty 😃
Cheers
@KingDarBoja That issue seems to have been fixed, and included as far back as rc.11: https://github.com/angular/angular/compare/9.0.0-rc.11...master
Rebroken, maybe?
Updating to Angular 9 trigger these warning and error logs:
Waiting for some release in the meantime.
I’m pretty sure that’s not an issue with the template checker.
It seems to be an issue with the module using the spread operator and how it is pre-compiled (apparently it’s targeted for old JS?), which makes the compiled module be a function instead of an array:
amplify-angular-module.ts:Precompiled
aws-amplify-angular.module.js:I had the similar issue and this is how I resolved it. Go to the angular.json file then search for aot and if the value of aot is true then replace it with false.
Hi
Just wondering if anyone has any fix for this item as of yet? Are folks not using IVY until there is a fix so we can use the Authentication Module with Ivy?
Thanks Damien
@damogallagher Here is what I did:
Then it required me to update another unrelated package, which I did and BAM it worked, Ivy and all
Angular 9.0.3 has been released. Does this issue still exist?
The following Angular 9 issues would seem relevant and they have been closed.
https://github.com/angular/angular/pull/35191 https://github.com/angular/angular/issues/35388
I’m looking into this, but we do have a note in our docs regarding Ivy support:
@alexAlchemy Have you switched your rendering engine to Ivy in Angular 9 or have you already opted for Ivy in your Angular 8 project? At the moment there are issues with template checking and/or ivy renderer. You could try switching off Ivy and disabling “fullTemplateTypeCheck” in your angularCompilerOptions in tsconfig.json