为生产而构建时,Angular 4应用程序将无法工作 [英] Angular 4 app won't work when built for production

查看:64
本文介绍了为生产而构建时,Angular 4应用程序将无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署我的第一个Angular 4应用,但遇到了严重的问题.

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)

我不知道如何调试它.

要构建服务器,我运行了命令: ng build --prod

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

我还尝试了: ng server --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)

编辑

我已经重新安装了Angular CLI并创建了一个新应用,我将旧代码(index.html和应用文件)复制到了新应用中,并且存在相同的问题.

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.

我现在可以肯定地说,我相信问题出在我编写的代码中.但是我不知道要看哪里,我已经(逐字地)搜索了我更改过的每个文件,并且没有任何 create 属性.

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?

我运行了 ng build --prod --sourcemap = true 命令,并在日志开头收到了此警告

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?

此外,在gamerfinder.net/dev上运行的构建是我从上述命令获得的构建,现在我没有得到无法获取属性'create'错误,相反,我得到了每个文件的语法错误(您可以通过访问链接查看).

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).

该应用程序的全部代码可以在GitHub上找到,以供任何希望查看它的人使用.

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

推荐答案

我安装了您的项目,但是遇到了构建问题.我通过将 CLI 更新为 1.2.7 来解决了这一问题.发生这种情况的原因可能是您为 CLI 使用了固定版本,但使用了最新的角度版本.我建议您使用 ^ 1.2.7 作为 CLI 版本.

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.

接下来,我遇到了与您相同的问题.这很容易解决.从您的 app.module.ts 中删除此行:

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);

不应该在那里.

PS.您的代码有点混乱.文件名带有大写字母,被遗忘的分号等.我建议您阅读样式指南,并在其中使用TSlint您的IDE.

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.

这篇关于为生产而构建时,Angular 4应用程序将无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆