angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Bug: Runtime TypeError ("Cannot read property 'call' of undefined")

Open ghost opened this issue 9 years ago • 93 comments

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..."): image Webpack is trying to get the module with the Id 0: image 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.

ghost avatar May 05 '17 13:05 ghost

Oh, @codeStuffs, I want to be happy like you, and promote @richardsengers to be a hero for all! But, my current zone.js is 0.8.12. And the deployment still doesn't work. Could you, please, provide me with a list of your main npm pacakges?

mariannafld avatar Jul 17 '17 11:07 mariannafld

Currently my project is running with these dependencies and without incidents since last webpack manual installation:

"dependencies": {
    "@angular/animations": "^4.3.0",
    "@angular/cdk": "^2.0.0-beta.8",
    "@angular/common": "^4.3.0",
    "@angular/compiler": "^4.3.0",
    "@angular/core": "^4.3.0",
    "@angular/flex-layout": "^2.0.0-rc.1",
    "@angular/forms": "^4.3.0",
    "@angular/http": "^4.3.0",
    "@angular/material": "^2.0.0-beta.8",
    "@angular/platform-browser": "^4.3.0",
    "@angular/platform-browser-dynamic": "^4.3.0",
    "@angular/router": "^4.3.0",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^2.0.4",
    "@ngrx/router-store": "^1.2.6",
    "@ngrx/store": "^2.2.3",
    "@ngrx/store-devtools": "^3.2.4",
    "@ngx-translate/core": "^7.0.0",
    "@ngx-translate/http-loader": "^0.1.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "howler": "^2.0.4",
    "redux": "^3.7.2",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.1",
    "@angular/compiler-cli": "^4.3.0",
    "@types/hammerjs": "^2.0.34",
    "@types/howler": "^2.0.2",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.83",
    "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-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "pug": "^2.0.0-rc.1",
    "pug-loader": "^2.3.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }

karlos1337 avatar Jul 17 '17 11:07 karlos1337

@mariannafld I've removed all the ^ from the packages so these are the versions which are installed

"dependencies": {
    "@agm/core": "1.0.0-beta.0",
    "@angular-mdl/core": "4.0.8",
    "@angular-mdl/popover": "0.6.3",
    "@angular-mdl/select": "0.10.4",
    "@angular/animations": "4.2.6",
    "@angular/cdk": "2.0.0-beta.8",
    "@angular/common": "4.2.6",
    "@angular/compiler": "4.2.6",
    "@angular/core": "4.2.6",
    "@angular/forms": "4.2.6",
    "@angular/http": "4.2.6",
    "@angular/material": "2.0.0-beta.8",
    "@angular/platform-browser": "4.2.6",
    "@angular/platform-browser-dynamic": "4.2.6",
    "@angular/router": "4.2.6",
    "@covalent/core": "1.0.0-beta.6",
    "@types/auth0-js": "8.6.2",
    "angular2-jwt": "0.1.28",
    "auth0-js": "7.6.1",
    "bootstrap": "4.0.0-alpha.6",
    "color-namer": "1.3.0",
    "core-js": "2.4.1",
    "css-element-queries": "0.4.0",
    "deep-extend": "0.5.0",
    "font-awesome": "4.7.0",
    "highcharts": "5.0.12",
    "medium-editor": "5.23.1",
    "moment": "2.18.1",
    "moment-timezone": "0.5.13",
    "mydatepicker": "2.0.24",
    "ng2-file-upload": "1.2.1",
    "ng2-slim-loading-bar": "4.0.0",
    "ng2-validation": "3.9.1",
    "ngx-color-picker": "4.1.0",
    "papaparse": "4.3.3",
    "rxjs": "5.1.0",
    "tether-shepherd": "1.8.1",
    "zone.js": "0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.2.1",
    "@angular/compiler-cli": "4.2.6",
    "@types/highcharts": "4.2.57",
    "@types/jasmine": "2.5.53",
    "@types/node": "6.0.60",
    "codelyzer": "3.0.1",
    "jasmine-core": "2.6.4",
    "jasmine-spec-reporter": "3.3.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.2.3",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "3.0.4",
    "tslint": "5.3.2",
    "typescript": "2.3.3"
  }

Hope this helps you a bit

richardsengers avatar Jul 17 '17 12:07 richardsengers

@mariannafld here is my list of npm packages


  "dependencies": {
    "@angular/animations": "^4.3.0",
    "@angular/cdk": "^2.0.0-beta.8",
    "@angular/common": "^4.3.0",
    "@angular/compiler": "^4.3.0",
    "@angular/core": "^4.3.0",
    "@angular/forms": "^4.3.0",
    "@angular/http": "^4.3.0",
    "@angular/material": "^2.0.0-beta.8",
    "@angular/platform-browser": "^4.3.0",
    "@angular/platform-browser-dynamic": "^4.3.0",
    "@angular/router": "^4.3.0",
    "angular2-moment": "^1.5.0",
    "angularfire2": "^4.0.0-rc.1",
    "core-js": "^2.4.1",
    "firebase": "^4.1.3",
    "hammerjs": "^2.0.8",
    "material-design-lite": "^1.3.0",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "node-sass": "^4.5.3",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.12"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.1",
    "@angular/compiler-cli": "^4.3.0",
    "@angular/language-service": "^4.3.0",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "^2.4.1"
  }

thatDeryk avatar Jul 17 '17 14:07 thatDeryk

Good day to all. Still, the problem exists:(.
These are dependencies from empty test project:

"dependencies": { "@angular/cli": "^1.3.0-beta.1", "@angular/common": "^4.3.0", "@angular/compiler": "^4.3.0", "@angular/core": "^4.3.0", "@angular/forms": "^4.3.0", "@angular/http": "^4.3.0", "@angular/platform-browser": "^4.3.0", "@angular/platform-browser-dynamic": "^4.3.0", "@angular/router": "^3.3.1", "core-js": "^2.4.1", "npm": "^5.2.0", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", "webpack": "^3.3.0", "webpack-dev-server": "^2.5.1", "zone.js": "^0.8.12" }, "devDependencies": { "@angular/compiler-cli": "^4.3.0", "@types/jasmine": "2.5.38", "@types/node": "^6.0.42", "codelyzer": "~2.0.0-beta.1", "jasmine-core": "2.5.2", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "~4.0.13", "ts-node": "1.2.1", "tslint": "^4.3.0", "typescript": "^2.4.1" }

One more thread I found that talk about the same problem in different context: https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/456 It is so easy to reproduce when creating new empty project http://www.telerik.com/blogs/using-kendo-ui-with-angular-2 (without installing kendo-ui ).

mariannafld avatar Jul 18 '17 11:07 mariannafld

@mariannafld First, change "zone.js": "^0.8.12" to "zone.js": "0.8.12" ... without the ^ Then ... remove your node_modules folder Then ... npm install

richardsengers avatar Jul 18 '17 12:07 richardsengers

Nothing.... I close to develop manic-depressive syndrome:) On each new item in the tread - I'm in 'Hi' On the suggest implementation - I'm in 'Down'

mariannafld avatar Jul 18 '17 12:07 mariannafld

Just started running into this issue after upgrading from 1.1.1 of the cli to 1.2

coryrylan avatar Jul 18 '17 13:07 coryrylan

Heya, can someone upload to github a project where I can run npm install && ng serve and see this behaviour?

filipesilva avatar Jul 18 '17 13:07 filipesilva

I don't have an easy way to upload a project but could be related to these

https://github.com/angular/angular-cli/issues/7021 https://github.com/webpack/webpack/issues/959

coryrylan avatar Jul 18 '17 13:07 coryrylan

I noticed, refreshing the remote machine's browser repeatedly, gets it working for me. I mean not always tho, but when it doesn't I do delete my node_modules folder and npm install, this temporarily fixes it, but when ever I install or import a new package it gets bugged up again. And I have to repeat my lucky process.

thatDeryk avatar Jul 19 '17 01:07 thatDeryk

I obviously understand this is something people are experiencing, but I cannot reproduce myself on a new project. Reports that this is also happening in your project are useful to determine impact, but not so much to figure out how to fix it.

So if you're experiencing this bug, and want to help getting it fixed, the absolute best way is to provide a simple reproduction that the CLI team can follow. Make a new project, add the bare minimum of code, upload to github, and post here with instructions on how to use the repro.

Ideally it should be as simple as git clone, npm install, ng serve, open browser, see console. The harder it is to reproduce, the less likely it will be fixed soon.

Once we have a repro, we can investigate and develop a solution against it.

filipesilva avatar Jul 19 '17 09:07 filipesilva

Dear friends, Sorry for disappearing for a month (was switched to another project). Filipesilva, per your request, I uploaded my project, created today from scratch: https://github.com/mariannafld/TestAngularCLI-Deployment

  1. Run: ng build --env=prod --output-hashing none
  2. move created dist folder to real device
  3. Exception: Uncaught SyntaxError: Unexpected token < bootstrap e48bca6c55378bbd138f:54 Uncaught TypeError: Cannot read property 'call' of undefined at webpack_require (bootstrap e48bca6c55378bbd138f:54) at Object.../../../../../src/main.ts (environment.ts:3) at webpack_require (bootstrap e48bca6c55378bbd138f:54) at Object.0 (main.ts:11) at webpack_require (bootstrap e48bca6c55378bbd138f:54) at webpackJsonpCallback (bootstrap e48bca6c55378bbd138f:25) at main.bundle.js:1

Thank you in advance

mariannafld avatar Aug 10 '17 09:08 mariannafld

I experience same problem in our application as well but only in the case I turn on In Chrome the Throttling to Slow 3G. @filipesilva maybe that can help to find it for you?

p.s.: I can experience it on simple npm start --aot=false ... prod build is with --aot=true -prod and it is happening as well

on @angular/[email protected] and also on new 1.3.0

rokerkony avatar Aug 11 '17 12:08 rokerkony

Also having the same issue :|

No idea what's actually causing it, so I can't re-create it......

douglasg14b avatar Aug 16 '17 16:08 douglasg14b

@filipesilva

The error is triggered by registering a callback on $transitions without defining the first parameter.

Example That Causes Error:

$transitions.onStart(() => {/* do stuff */});

Example That Does Not Cause Error

$transitions.onStart("*", () => {/* do stuff */});

douglasg14b avatar Aug 16 '17 16:08 douglasg14b

still having this problem with ng build --aot --prod --build-optimizer please angular cli team solve this issue I really need to run my project :(

DanialV avatar Aug 22 '17 00:08 DanialV

@Brocco can you investigate the repros provided?

filipesilva avatar Aug 31 '17 14:08 filipesilva

Any news? ng serve working fine but ng build and ng build --prod --env=prod is giving me that error.

Keeps me from publishing my application.

"dependencies": { "@agm/core": "1.0.0-beta.0", "@amcharts/amcharts3-angular": "1.4.0", "@angular/animations": "^4.4.0-RC.0", "@angular/cdk": "^2.0.0-beta.10", "@angular/compiler": "4.2.6", "@angular/core": "4.2.6", "@angular/forms": "4.2.6", "@angular/http": "4.2.6", "@angular/material": "^2.0.0-beta.10", "@angular/platform-browser": "^4.4.0-RC.0", "@angular/platform-browser-dynamic": "4.2.6", "@angular/router": "4.2.6", "@ngx-translate/core": "^7.2.2", "@ngx-translate/http-loader": "^1.0.2", "@swimlane/ngx-charts": "^6.0.2", "@swimlane/ngx-datatable": "9.3.0", "@types/leaflet": "1.0.63", "amcharts3": "3.21.2", "angular-calendar": "0.17.4", "axios": "^0.16.2", "bootstrap-sass": "^3.3.7", "chart.js": "2.6.0", "core-js": "2.4.1", "cross-env": "^5.0.1", "d3": "^4.9.1", "hammerjs": "2.0.8", "jquery": "^3.1.1", "laravel-mix": "^1.0", "leaflet": "1.0.3", "lodash": "^4.17.4", "ng-build": "^0.1.12", "ng-factory": "^1.1.0", "ng2-charts": "1.6.0", "ng2-validation": "4.2.0", "rxjs": "5.4.2", "squeezebox": "1.1.12", "vue": "^2.1.10", "zone.js": "0.8.12" }, "devDependencies": { "@angular/cli": "1.4.1", "@angular/common": "^4.3.6", "@angular/compiler-cli": "4.2.6", "@angular/language-service": "4.2.6", "@types/jasmine": "2.5.52", "@types/jasminewd2": "^2.0.3", "@types/node": "8.0.1", "axios": "^0.16.2", "bootstrap-sass": "^3.3.7", "codelyzer": "3.1.1", "cross-env": "^5.0.1", "jasmine-core": "2.6.4", "jasmine-spec-reporter": "4.1.1", "jquery": "^3.1.1", "karma": "1.7.0", "karma-chrome-launcher": "2.1.1", "karma-cli": "1.0.1", "karma-coverage-istanbul-reporter": "1.3.0", "karma-jasmine": "1.1.0", "karma-jasmine-html-reporter": "0.2.2", "laravel-mix": "^1.0", "lodash": "^4.17.4", "protractor": "5.1.2", "ts-node": "3.1.0", "tslint": "5.4.3", "typescript": "2.3.4", "uglify-js": "^2.8.29", "undertaker-app-tasks": "^0.5.2", "vue": "^2.1.10" }

MazzMazz avatar Sep 09 '17 13:09 MazzMazz

Hey guys, i just fixed it for me 👍

My problem was, that i included the *.bundle.js files in the wrong order. I loaded them dynamically via PHP (because of the different hashes generated in the prod version) and included them in my blade.php file (alphabetically by default)

@foreach($jsBundles as $bundle) @endforeach

I was wondering why ng serve worked but ng prod not so i included them in this order

inline.bundle.js polyfills.bundle.js scripts.bundle.js vendor.bundle.js main.bundle.js

And now it is working again. Maybe it will help one or another

MazzMazz avatar Sep 15 '17 11:09 MazzMazz