为生产而构建时,Angular 4 应用程序将无法运行

标签 angular

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

每当我尝试加载应用程序时,我都会收到此错误:

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

我不知道如何调试它。

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

我也试过:ng server --prod 实际上给了我这个错误两次,还有上面那个

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

编辑

我重新安装了 Angular CLI 并创建了一个新应用程序,我将旧代码(index.html 和应用程序文件)复制到新应用程序中并遇到了同样的问题。

只是为了确定我创建了另一个应用程序,没有做任何更改并运行了它。

我现在可以肯定地说,我认为问题出在我编写的代码中。但我不知道去哪里找,我已经(从字面上)搜索了我更改过的每个文件,但没有任何文件具有 create 属性。

有没有办法在不丑化代码的情况下构建我的生产应用?

更新

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

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

不推荐使用的代码是否会导致问题?

此外,在 gamerfinder.net/dev 上运行的构建是我从上述命令获得的构建,我现在没有得到 Unable to get property 'create' 错误,而是得到每个文件的语法错误(您可以通过访问链接看到)。

应用程序的完整代码 can be found on GitHub对于任何想看的人。

最佳答案

我安装了您的项目,但遇到了构建问题。我通过将 CLI 更新为 1.2.7 解决了这个问题。这可能是因为您为 CLI 使用了固定版本,但使用了最新的 Angular 版本。我建议你使用 ^1.2.7 作为 CLI 版本。

接下来我遇到了和你一样的问题。这很容易解决。从您的 app.module.ts 中删除这一行:

platformBrowserDynamic().bootstrapModule(AppModule);

它不应该在那里。

附言。你的代码有点乱。带有大写字母、忘记分号等的文件名。我建议你阅读the style guide并在您的 IDE 中使用 TSlint。

关于为生产而构建时,Angular 4 应用程序将无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45495675/

相关文章:

Angular 6 - 错误类型错误 : Cannot read property 'value' of undefined

Angular Material Dialog -> afterClosed -> 按下了哪个按钮

angular - 使用 ng new 命令创建项目时项目名称无效

html - hide 设置为 false 后聚焦输入

angular - @angular/flex-layout 不适用于@HostBinding

javascript - Angular 前端未对 Flask 应用程序进行休息调用

javascript - 如何将 NGBootstrap 工具提示附加到 Font Awesome 图标

angular - 无法访问父组件中的@ViewChildren

javascript - Angular Reactive Forms 中所需重叠的电子邮件验证

css - Angular Material : displaying icons to the right of mat-chip