未捕获的TypeError:this._input.charCodeAt不是函数

The*_*eal 9 webpack angular2-cli angular

我使用Angular 2 CLI创建了一个Angular 2项目并使用了ng build --prod命令并且没有错误.

当我将dist文件夹上传到我的网站时,我在应用加载时收到以下错误:

在此输入图像描述

Uncaught TypeError: this._input.charCodeAt is not a function_Tokenizer._advance @ main .688167 c….bundle.js: 1716 _Tokenizer @ main .688167 c….bundle.js: 1716 tokenize @ main .688167 c….bundle.js: 1709 Parser.parse @ main .688167 c….bundle.js: 219 HtmlParser.parse @ main .688167 c….bundle.js: 380 DirectiveNormalizer.normalizeLoadedTemplate @ main .688167 c….bundle.js: 598 DirectiveNormalizer.normalizeTemplateSync @ main .688167 c….bundle.js: 598 DirectiveNormalizer.normalizeDirective @ main .688167 c….bundle.js: 598 RuntimeCompiler._createCompiledTemplate @ main .688167 c….bundle.js: 1090(anonymous
function) @ main .688167 c….bundle.js: 1090(anonymous
function) @ main .688167 c….bundle.js: 1090 RuntimeCompiler._compileComponents @ main .688167 c….bundle.js: 1090 RuntimeCompiler._compileModuleAndComponents @ main .688167 c….bundle.js: 1090 RuntimeCompiler.compileModuleAsync @ main .688167 c….bundle.js: 1090 PlatformRef_._bootstrapModuleWithZone @ main .688167 c….bundle.js: 717 PlatformRef_.bootstrapModule @ main .688167 c….bundle.js: 717(anonymous
function) @ main .688167 c….bundle.js: 1509 __webpack_require__ @ inline.js: 1(anonymous
function) @ main .688167 c….bundle.js: 2131 __webpack_require__ @ inline.js: 1 window.webpackJsonp @ inline.js: 1(anonymous
function) @ main .688167 c….bundle.js: 1
Run Code Online (Sandbox Code Playgroud)

我正在使用最新的Angular 2 CLI和webpack以及Angular 2 RC.7

什么可能出错?

this._input.charCodeAt仅在如下的角度编译文件夹中: 在此输入图像描述

tom*_*bak 48

可能是由加载组件代码而不是模板引起的,即

templateUrl: 'my.component'
Run Code Online (Sandbox Code Playgroud)

代替

templateUrl: 'my.component.html'
Run Code Online (Sandbox Code Playgroud)

  • 刚过来说,救了我的一天. (2认同)

小智 10

原始加载器已更改。需要 xlf 文件时,您必须使用.default

const translations = require('raw-loader!./i18n/messages.ko.xlf').default;
Run Code Online (Sandbox Code Playgroud)

当我在我的 angular 项目中将 @ngx-translate/i18n-polyfill 更新到版本 1.0.0 时,我遇到了同样的问题。当我实施上述更改时,问题已解决

参考:ngx-translate/i18n-polyfill Issue#60