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

Had the same error.   Solved.  I have my own "index.html" for integration purpose in rails. There I mixed up the sequence of javascript-file loading.

if you turn the line main.bundle.js and the line vendor.bundle.js this error happens.  In my case it was a matter of loading sequence.

`
<base href="/">
<app-root>Lade Vordialog...</app-root>

.......


<![if IE]>
<script type="text/javascript" src="ang/inline.bundle.js"></script>
<script type="text/javascript" src="ang/styles.bundle.js"></script>
<script type="text/javascript" src="ang/vendor.bundle.js"></script>
<script type="text/javascript" src="ang/main.bundle.js"></script>
<![endif]>
`

erhard avatar Dec 11 '17 17:12 erhard

@erhard Cool guy ! l have set __Zone_enable_cross_context_check = true to solve some issues under IE and forgot to add <!if IE> annotation so that chrome doesn't work fine. You made me realize that. [BUG] IE11 -> Can't execute code from a freed script

Poseiden avatar Dec 13 '17 07:12 Poseiden

Using latest Angular CLI 5. I inexplicably started getting this error in IE during development, though Chrome was fine. I reverted all my changes since before the error began, error was still there. I restarted 'ng serve' but the error was still there. I closed the browser window and opened another and it went away. Weird.

esoyke avatar Dec 18 '17 18:12 esoyke

This fixed it for me ng build --env=prod --output-hashing none

FernandoX7 avatar Jan 13 '18 20:01 FernandoX7

The idea from @FernandoX7 and others doesn't help much, for those of us who want output hashing.

kylecordes avatar Jan 16 '18 19:01 kylecordes

I ran into this exact same problem with a Vue.js project tonight. Updating webpack 3.6.0 to 3.10.0 fixed it for me.

pbredenberg avatar Jan 17 '18 00:01 pbredenberg

@filipesilva Hello filipesilva we have also the same problem in our project , it work correctly with ng serve ( dev mode ) but not on the server. In AOT mode ( -prod) i noted that the script vendor scripts bundle is missing even with empty new project , is'it normal ? Thank you !

hamouda06 avatar Jan 18 '18 09:01 hamouda06

@filipesilva - here is a repro: https://github.com/webpack/webpack/issues/959#issuecomment-358968281

https://github.com/KillerCodeMonkey/ngx-quill/issues/102

varadero avatar Jan 20 '18 20:01 varadero

I had the same problem where everything was working then failed. using @FernandoX7 worked

ng build --prod --aot --output-hashing none

michaelwaihenya avatar Jan 22 '18 07:01 michaelwaihenya

There are various references to the --output-hashing none workaround... it works, but it's a problem for those of us who need output hashing on. A different workaround also gets things back up and running: --common-chunk false, though it's not clear how much this affects output size for various projects. It was discussed at length in #7021.

kylecordes avatar Jan 22 '18 13:01 kylecordes

Hello,

In our case it was an import of third part library that cause the error ....

hamouda06 avatar Jan 22 '18 15:01 hamouda06

@kylecordes The workaround I found at: https://github.com/webpack/webpack/issues/959#issuecomment-358968281

is to add --sourcemaps:

ng build --prod --sourcemaps

@hamouda06 - In my case too - importing QuillModule from ngx-quill

varadero avatar Jan 22 '18 17:01 varadero

Updating to the recent @angular/[email protected] version has resolved this issue for me.

andyrue avatar Jan 31 '18 14:01 andyrue

@andyrue I can confirm the same. Just upgraded from Angular-CLI 1.6.5 to 1.6.6 and the issues is now gone.

varadero avatar Jan 31 '18 18:01 varadero

I was hitting this same problem with prod builds. Workaround was to add --sourcemaps to the ng build command line. Without this parameter I keep hitting the problem

aford22 avatar Feb 09 '18 16:02 aford22

I was running into this issue when doing a dotnet run build without doing a ng production build first.

bitsagarob avatar Mar 05 '18 13:03 bitsagarob

anyone find any solution :)

riturajratan avatar Mar 06 '18 10:03 riturajratan

try ng update if none of the above works for you

richardsengers avatar Mar 06 '18 13:03 richardsengers

Simply add the scripts in below mentioned order and it will work 👍

`

`

Happy Coding !!!

Thanks, Ravin

ravinsingh890 avatar May 07 '18 10:05 ravinsingh890

still getting this error...

my zone.js version is 0.8.18 so i don't think it still has the bug in version 0.8.13

and the order of scripts in my index.html is exactly as recommened: main.bundle.js goes after vendor.bundle.js

shuodongLou avatar May 08 '18 08:05 shuodongLou