Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 app won't work when built for production

Tags:

angular

I'm trying to deploy my first Angular 4 app and I'm having a serious issue.

Whenever I try to load the app I get this error:

SCRIPT5007: Unable to get property 'create' of undefined or null reference
vendor.8f08e50eff049f37e041.bundle.js (1,93870)

I have no idea how to debug this.

To build the server I ran the command: ng build --prod

I also tried: ng server --prod which actually gave me this error twice, as well as the one above

SCRIPT5011: Can't execute code from a freed script
polyfills.3ae08eaf6129a55130cb.bundle.js (1,30944)

Edit

I have reinstalled Angular CLI and created a new app, I copied the old code (the index.html and app files) into the new app and have the same problem.

Just to be certain I created another app, made no changes and ran it.

I can now say with certainty that I believe the problem is in the code I've made. but I don't know where to look, I've searched through (literally) every file that I've made changed to and there is nothing with a create property.

Is there a way to build my app for production without uglifying the code?

Update

I ran the ng build --prod --sourcemap=true command and I got this warning at the start of the log

The <template> element is deprecated. Use <ng-template> instead ("
[WARNING ->]<template [ngIf]="!isClosed">
  <div [class]="'alert alert-' + type" role="alert" [ngClass]="classes""): ng:///C:/Users/jamie/Desktop/play/node_modules/ngx-bootstrap/alert/alert.component.d.tsHash: 4607d21b2e5e9f27bd39

Can deprecated code be causing the problem?

Also, the build running at gamerfinder.net/dev is the build I got from the above command, I now don't get the Unable to get property 'create' error, instead I get a syntax error for each file (which you can see by visiting the link).

The entire code for the app can be found on GitHub for anyone who wants to look at it.

like image 224
Jamie McAllister Avatar asked Aug 03 '17 22:08

Jamie McAllister


People also ask

How do I know if Angular is running in prod mode?

Simply check the production variable present in the environment file, it will be true for production mode and false for development. import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' import { enableProdMode } from '@angular/core'; import { AppModule } from './app.

How do you make an application in production mode?

The easiest way to start an application in production mode is to use the start command from the Play console. This requires a Play installation on the server. When you run the start command, Play forks a new JVM and runs the default Netty HTTP server.

Which command is used to build application in production mode in Angular?

To build your application for production, use the build command. By default, this command uses the production build configuration. This command creates a dist folder in the application root directory with all the files that a hosting service needs for serving your application.


1 Answers

I installed your project, but faced a build issue. I solved it by updating the CLI to 1.2.7. This probably happend because you use a fixed version for the CLI but use the newest angular version. I suggest you use ^1.2.7 as CLI version.

Next I had the same problem as you. It is very easy to solve. Remove this line from your app.module.ts:

platformBrowserDynamic().bootstrapModule(AppModule);

It is not supposed to be there.

PS. your code is a bit messy. File names with capital letters, forgotten semicolons, etc. I suggest you read the style guide and use TSlint in your IDE.

like image 56
Robin Dijkhof Avatar answered Oct 19 '22 19:10

Robin Dijkhof