dist文件Angular 2中出现错误 [英] Error in dist files Angular 2

查看:67
本文介绍了dist文件Angular 2中出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在stackoverflow上的大家好,我正在尝试发布Angular 2应用程序,但是 dist 文件存在问题.首先,我要做的是:

  • 清理 node_modules 目录并删除 package-lock.json
  • 运行 npm install ,然后运行 npm update 命令
  • 之后,我运行 ng build --prod ,一切都很好.

因此,我检查了 dist 文件夹并将其复制到我的服务器上,当我尝试访问它时向我显示错误:

未捕获的TypeError:无法读取未定义的属性"create"在vendor.7bb6292ce7eeab342f9a.bundle.js:1在e.invoke上(polyfills.0963b44a58b5526cfab7.bundle.js:1)在Object.onInvoke(vendor.7bb6292ce7eeab342f9a.bundle.js:1)在e.invoke上(polyfills.0963b44a58b5526cfab7.bundle.js:1)在r.run(polyfills.0963b44a58b5526cfab7.bundle.js:1)在t.run(vendor.7bb6292ce7eeab342f9a.bundle.js:1)在e._bootstrapModuleFactoryWithZone(vendor.7bb6292ce7eeab342f9a.bundle.js:1)在e.bootstrapModuleFactory(vendor.7bb6292ce7eeab342f9a.bundle.js:1)在Object.cDNt(main.e10f9a0cb71451c87757.bundle.js:1)在n(inline.d31757e5f12d693ae92a.bundle.js:1)

我知道这是一个与库相关的问题,因为minify不能按预期工作,但是我不知道哪个库正在这样做,因为 ng serve 可以正常工作并且没有显示错误.

我不知道是否有某种方法可以调试哪个库正在发生此错误或它来自何处.

这是我执行 ng build --prod 命令时得到的.另外,我已经包含了 enableProdMode(); 函数.

更新

谢谢大家,问题是在我的 app.module.ts 中,我有 platformBrowserDynamic().bootstrapModule(AppModule); ,这是一个错误,因为在更新的版本现在位于 main.ts 中,而不是 app.module.ts 中,因此我重复了此步骤,现在一切正常.谢谢!

解决方案

您是否已在此处看到此错误的问题: https://github.com/angular/angular-cli/issues/5181 这表明main.ts中的platformBrowserDynamic设置可能有问题,特别是如果此应用程序是从较旧/不同版本的Angular或CLI开始.

我的main.ts看起来像这样:

 从"@ angular/core"导入{enableProdMode};从'@ angular/platform-b​​rowser-dynamic'导入{platformBrowserDynamic};从'./app/app.module'导入{AppModule};从"./environments/environment"导入{环境};如果(environment.production){enableProdMode();}platformBrowserDynamic().bootstrapModule(AppModule); 

Hi everyone at stackoverflow, I'm trying to release my Angular 2 app but I'm having issues with the dist files. First what I do is:

  • Clean the node_modules dir and remove the package-lock.json
  • Run the npm install and then npm update commands
  • After that I run the ng build --prod and everything is fine.

So, I check the dist folder and copy it to my server, and when I try to access it shows me an error:

Uncaught TypeError: Cannot read property 'create' of undefined at vendor.7bb6292ce7eeab342f9a.bundle.js:1 at e.invoke (polyfills.0963b44a58b5526cfab7.bundle.js:1) at Object.onInvoke (vendor.7bb6292ce7eeab342f9a.bundle.js:1) at e.invoke (polyfills.0963b44a58b5526cfab7.bundle.js:1) at r.run (polyfills.0963b44a58b5526cfab7.bundle.js:1) at t.run (vendor.7bb6292ce7eeab342f9a.bundle.js:1) at e._bootstrapModuleFactoryWithZone (vendor.7bb6292ce7eeab342f9a.bundle.js:1) at e.bootstrapModuleFactory (vendor.7bb6292ce7eeab342f9a.bundle.js:1) at Object.cDNt (main.e10f9a0cb71451c87757.bundle.js:1) at n (inline.d31757e5f12d693ae92a.bundle.js:1)

I know is a library related issue because the minify is not working as intended, but I don't know which library is doing that since ng serve is working fine and showing no errors.

I don't know if there is some way to debug which library is doing this error or where it comes from.

This is what I get when I do the ng build --prod command. Also I included the enableProdMode();function already.

Update

Thanks everyone, the issue was that in my app.module.tsI had the platformBrowserDynamic().bootstrapModule(AppModule); and it was an error because in an updated version is in main.ts now and not in the app.module.ts so I had this duplicated and now everything is working fine. Thanks!

解决方案

Have you seen the issue for this error here: https://github.com/angular/angular-cli/issues/5181 It suggests that it may be a problem with the platformBrowserDynamic setup in main.ts, especially if this app was started with an older/different version of Angular or the CLI.

My main.ts looks like this:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

这篇关于dist文件Angular 2中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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