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.
I haven't seen any similar issues yet, so without a repro there isn't much we can do to investigate. Can you try to make a simple one that we can look at? It might be something simple but there's just no way of knowing without a repro.
This issue is related to https://github.com/webpack/webpack/issues/959 and https://github.com/AngularClass/angular-starter/issues/456. But since webpack config is embedded in cli, we cannot apply the same fix.
Getting the same error. Locally it works fine, but fails in my dev server
i had this issue and it was because i was not including vendor.bundle.js
Getting the same error. Locally it works fine, but in production some times it fails. any solution please
Same here, locally works but not in production
TL;DR: the solution provided here was a false hope, not solving the issue
I had the same issue when I uploaded the www folder built by ionic serve to my website. I found that if I instead build using npm run ionic:build --prod, this problem appears to have been solved.
Edit: Here is the post where I found the solution
Edit2: It seems that the problem has not resolved only less frequent in my use case.
@Leffe108 If Ionic-cli is like angular-cli you musn't use serve for production, that is only for development cause it start a new webpack-server (node) and dont need that only for build the production app, besides in the first instruction you are not setting the env vars, maybe that is the error.
In my case the error is just the oposite, ng server build a pack that works in local, in production pipeline I use ng build and it dont works, both with same env vars.
Edit: I manually install webpack@latest and webpack-dev-server@latest and it works but I guess it should be arranged by other way
Hello all, The same problem: works OK locally and Fails in production (ng build --env=prod --output-hashing none). Two days fighting with this issue. All npm packages are up to date. Please, provide with any update.
Sorry for getting a bit of topic including ionic commands above. But to get to a solution the team member above asked for a simple repo or steps to reproduce. So to get forward we need to find out what a minimal repo that reproduces this looks like and provide it to the team so the problem can get solved.
Same error here ... the error doesn't help much to debug....quite annoying Manually installing webpack@latest and webpack-dev-server@latest didn't do the trick for me. I'm getting all kind of eror messages from webpack while building
Dear Leif Linse,
To localize the problem, I do the following
-
Build the project from scratch “kendo-ui-first-look” followed by http://www.telerik.com/blogs/using-kendo-ui-with-angular-2. -
Update to the latest packages: npm, webpack, @angular/cli, webpack-dev-server. -
Running: ng build --env=prod --output-hashing none -
Transfer dist to the machine (with Lighttpd server) -
Launch in Chrome
The same problem occurs on this virgin project. Thank you in advance, Marianna
For me the error is gone with 1.3.0-beta.1
mariannafld: Thanks for providing a way to reproduce it. I'm sorry if I sounded like I could fix it, but I just re-read the status of the thread and saw that a lot of people had the problem, but none had answered the question from Angular member to provide repo or steps to reproduce.
But if it is solved in 1.3.0-beta.1 it may be that the team found a way to reproduce it or fix it anyway.
Update @angular/cli to version 1.3.0-beta.1 did not solved the problem for me. Angular team, please, try to reproduce this in clean project http://www.telerik.com/blogs/using-kendo-ui-with-angular-2 (without installing kendo-ui ). Thank you in advance
Hmmm... What version of typescript are you using? Also updating typescript to the latest version fixes it for me, it wasn't just only the new beta version of angular-cli. I was on Typescript 2.3.4 and I'm now on 2.4.1
Seems like there's no fix to this issue yet. The funny thing is, 1 min it was working fine and the next min boom things fell apart.
Yes... Still no solution. Typescript update didn't lead to desired results:(.
@codeStuffs ah thanks...I thought I was going crazy but apperently I'm not the only one were things are working fine and the next time not. :-) Ayway... did you already put zone.js to version 0.8.12 instead of 0.8.13? Zone.js has a bug in 0.8.13. Angular cli has fixed zone.js to 0.8.12 but offcourse that is only for a new project you start.
Maybe this could help https://github.com/angular/angular-cli/pull/6971
@richardsengers you are my hero. lol. I downgraded zone.js to 0.8.12 and voilà! it worked.