Bug: Runtime TypeError ("Cannot read property 'call' of undefined")
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
General information
We have an Angular 2 application running and I was asked to upgrade Angular (including it's CLI) to the newest version (Note: I'm not really involved in the project, so I don't know how the application is built or where the dependencies are used). I tried upgrading using the 1.0 update guide. Building the app with ng build works (no error messages), but when I navigate to the website, I get an error message in the console.
Versions
@angular/cli: 1.0.2
node: 7.9.0
os: win32 x64
@angular/animations: 4.1.1
@angular/common: 4.1.1
@angular/compiler: 4.1.1
@angular/core: 4.1.1
@angular/forms: 4.1.1
@angular/http: 4.1.1
@angular/platform-browser: 4.1.1
@angular/platform-browser-dynamic: 4.1.1
@angular/router: 4.1.1
@angular/cli: 1.0.2
@angular/compiler-cli: 4.1.1
Repro steps / packages
I don't know what exactly causes this issue, therefore I don't know how to reproduce it. packages.json
...
"dependencies": {
"@angular/animations": "^4.1.1",
"@angular/common": "^4.1.1",
"@angular/compiler": "^4.1.1",
"@angular/core": "^4.1.1",
"@angular/forms": "^4.1.1",
"@angular/http": "^4.1.1",
"@angular/platform-browser": "^4.1.1",
"@angular/platform-browser-dynamic": "^4.1.1",
"@angular/router": "^4.1.1",
"@ngx-translate/core": "^6.0.1",
"@webcomponents/custom-elements": "^1.0.0-rc.3",
"clarity-angular": "^0.9.3",
"clarity-icons": "^0.9.3",
"clarity-ui": "^0.9.3",
"core-js": "^2.4.1",
"moment": "^2.18.1",
"mutationobserver-shim": "^0.3.2",
"ng2-file-upload": "^1.2.1",
"ngx-bootstrap": "^1.6.6",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.3.1",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.10"
},
"devDependencies": {
"@angular/cli": "~1.0.2",
"@angular/compiler-cli": "^4.1.1",
"@types/jasmine": "2.5.47",
"@types/node": "~7.0.18",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~3.0.4",
"tslint": "~5.2.0",
"typescript": "~2.2.0",
"webpack": "~2.5.0"
}
}
.angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
...
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"../../Content/less/clarity/datagrid.css",
"../node_modules/clarity-icons/clarity-icons.min.css",
"styles.css"
],
"scripts": [
"../node_modules/core-js/client/shim.min.js",
"../node_modules/mutationobserver-shim/dist/mutationobserver.min.js",
"../node_modules/@webcomponents/custom-elements/custom-elements.min.js",
"../node_modules/clarity-icons/clarity-icons.min.js",
"../node_modules/web-animations-js/web-animations.min.js",
"../node_modules/reflect-metadata/Reflect.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
...
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
The log given by the failure
I get this console error message at runtime (application is then stuck at "Loading..."):
Webpack is trying to get the module with the Id 0:
modules[0] is undefined though.
Although when checking stats.json using the webpack analyzer, the module with the id 0 (./~/@angular/core/@angular/core.es5.js) exists.
Desired functionality
Proper bootstrapping of the application.
Mention any other details that might be useful
Someone had a similar problem and according to sokra this issue was fixed in 2.5.0. I got version 2.5.0 of webpack and put it manually in the node_modules folder of angular cli but the issue still persists. When I create a new application using ng new [name], it works fine. As soon as I put my src files and my dependencies in there I get this error.
MazzMazz, thank you for your input. Unfortunately, it didn't worked for me. Angular CLI team, please, try to provide us with a solution. It is become so crucial for my project! There is another thread here (Uncaught TypeError: Cannot read property ‘call’ of undefined in Chrome #1847) with the same problem. Maybe this link will give some hint? http://gonodejs.com/2017/01/24/node-js-angularjs2-cannot-read-property-call-of-undefined-when-bootstrapping/ Thank you in advance
@MazzMazz
thanks for pointing me to the right direction!
For a stupid reason (wanted to list in the alphabetical order all bundles imported) I put "main" before "vendor" and the 'call on undefined' error appeared.
After restoring the strict order as in the index.html generated by the CLI everything is fine again :-)
I'm still getting a similar error running
- CLI 1.5.0-beta.2
- TS 2.5.3
- rxjs 5.4.2
Running
ng build --prod --build-optimizer
Builds successfully but then at run time when lazy loading a module it shoots out the following error:
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'call' of undefined
TypeError: Cannot read property 'call' of undefined
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/Subscriber.js (index.js:34027)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/util/toSubscriber.js (index.js:35882)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/Observable.js (index.js:33493)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/add/operator/map.js (index.js:34524)
at __webpack_require__ (index.js:35)
at Object../src/index.ts (index.js:36696)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/Subscriber.js (index.js:34027)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/util/toSubscriber.js (index.js:35882)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/Observable.js (index.js:33493)
at __webpack_require__ (index.js:35)
at Object../node_modules/rxjs/add/operator/map.js (index.js:34524)
at __webpack_require__ (index.js:35)
at Object../src/index.ts (index.js:36696)
at resolvePromise (zone.js:824)
at resolvePromise (zone.js:795)
at zone.js:873
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
at drainMicroTaskQueue (zone.js:602)
at <anonymous>
Has there been any development in this issue?
Hi all, I'm trying to figure out what's happening here but I'm getting a lot of conflicting reports/repros. Some people mention build optimizer but some also don't, some say it only happens on deploy others say it's also serve.
The root cause of this problem seems to be related to script loads.
So for @mariannafld, @rokerkony and @MazzMazz's report it sounds like it's related to how you deploy: you might be serving some scripts out of order and then some modules are not available.
@DanialV and @RicardoVaranda mention --build-optimizer specifically, and that might mean it's malfunctioning and removing some modules that are needed.
But I must reiterate: I need a repro to investigate. If you are experiencing this please setup a simple repro from a new project, make the least changes possible for me to see it, upload it to github, and let me know what steps to follow.
@RicardoVaranda has provided a reproduction in https://github.com/RicardoVaranda/BuildOptimizerBug. Will investigate.
After setting script.async = false; I'm still getting the below error while deploying the application. Uncaught TypeError: Cannot read property 'call' of undefined at webpack_require (bootstrap b67e0d5dd7bab816096c:54) at Object.../../../../../src/main.ts (ui.component.ts:10) at webpack_require (bootstrap b67e0d5dd7bab816096c:54) at Object.0 (.*$:105) at webpack_require (bootstrap b67e0d5dd7bab816096c:54) at webpackJsonpCallback (bootstrap b67e0d5dd7bab816096c:25) at main.bundle.js:1 Has there any solution been identified for this issue
This definitely isn't a fix by any means but clearing the cache in chrome fixes it temporarily for our team. The problem still comes up every now and again but it at least fixes it for a while so we can keep working.
For people having the Runtime TypeError ("Cannot read property 'call' of undefined") error when using --build-optimizer, there is a fix in https://github.com/angular/devkit/pull/201. This fix should be released in @angular-devkit/[email protected].
This bug affected libraries packages with webpack. The problem was that build optimizer added require() calls to tslib, that failed lookup since since the library had its own custom __webpack_require__ function (with its own list of modules).
For users that get the Runtime TypeError ("Cannot read property 'call' of undefined") error when NOT using --build-optimizer, please provide a minimal repro.
You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.
So far the cases I've seen seem related to the way code is being deployed. If you are using a custom index.html and include script tags out of order from dist/index.html, you will get this error. Make sure to use the same order.
This error generally means that Webpack was not able to find a module the application needs. If you include scripts out of order, you might not have all the packages you need loaded at the right time.
An update to bootstrap version to 1.9.3 has resolved the issue in our team. And was required to do browser refresh continuously initially to get it work. Package.json was updated with the below version for ngx-bootstrap "ngx-bootstrap": "^1.9.3"
Can someone explain a fix as 'dumbed down' as possible? Im not loading my scripts in a weird way just got a normal app ive got angualr material on and im getting this ever, how do i apply this 'fix'?
edit: I just ran this
ng build --prod --base-href /new/ --build-optimizer
and it has compiled onto my live server fine?
Made a post on stackoverflow outlining the problem and the current solution, If I should add more information/am missing anything there please @ me here with what I should update @filipesilva is my post relevant/suitable?
https://stackoverflow.com/questions/46720805/cannot-read-property-call-of-undefined-angular-2-build-error-potential-solu/46720806?noredirect=1#comment80388366_46720806
@filipesilva,
The simple application to test deployment problem is uploaded to github.
https://github.com/mariannafld/SysMngCommunicator.
Navigate to http://localhost:3200/.
For deployment following command is used:
ng build --env=prod --output-hashing none
@kenji-1996 the fix for people having this problem with build optimizer is to reinstall node_modules, which should pick up @angular-devkit/[email protected] automatically. You can check which version you have with npm ls @angular-devkit/build-optimizer.
@mariannafld in your repro project I tried running ng build --env=prod --output-hashing none and opening http://localhost:4200/ in my browser. I did not see any error. If I had to bet you're running into cache problems on your deployment, but that's not something we can help you with here.
@filipesilva updated my stackoverflow post to include the new information you gave me, Thanks!
https://stackoverflow.com/questions/46720805/cannot-read-property-call-of-undefined-angular-2-build-error-potential-solu/46720806#46720806
I'm getting a similar runtime error
polyfills.bundle.js:formatted:3431 Uncaught TypeError: Cannot read property 'type' of undefined
Running cli 1.4.0
I'm getting this error while running the starter

steps:
- update to ionic@latest
- ionic start appName super
- ionic serve
repo: https://github.com/bookofdom/ionic-issue
ionic cached serviceworker.js caused the problem for me. had it enabled initially. then commented it out. but it was still cached in browser. cleared cache and works fine now.
@richardsengers Thanks it worked. I had zone.js 0.8.14 and downgrading it to 0.8.12 fixed the issue
I had a similar issue with this but just running a fresh npm install fixed the problem, so not sure what particular mismatch it was in terms of dependencies.
Like having fun with the GAC all over again!
This issue also still persists with webpack v3.8.1, node v8.9.1 and angular v5.0.3. Downgrading zone.js to v0.8.12 does not work.