11

我使用 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

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

可能出了什么问题?

this._input.charCodeAt仅在 Angular 编译器文件夹中使用,如下所示 :在此处输入图像描述

4

3 回答 3

48

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

templateUrl: 'my.component'

代替

templateUrl: 'my.component.html'
于 2016-09-28T09:29:55.290 回答
10

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

const translations = require('raw-loader!./i18n/messages.ko.xlf').default;

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

参考:ngx-translate/i18n-polyfill 问题#60

于 2019-11-05T11:23:15.930 回答
0

以下调试代码帮助我找出错误导入的模板。

_Tokenizer将下一个片段注入您./node_modules/@angular/compiler/bundles/compiler.umd.js(或其他使用的捆绑包)中的编译器:

function _Tokenizer(_file, _getTagDefinition, _tokenizeIcu, _interpolationConfig) {
    // ...
    try {
        this._advance();
    } catch (e) {
        console.log('[Tokenizer Error]: ' + _file && JSON.stringify(_file, null, 2));
        throw e;
    }
}

以截图为例:

在此处输入图像描述

于 2016-10-12T15:11:03.963 回答