【问题标题】:Uncaught TypeError: this._input.charCodeAt is not a function未捕获的 TypeError:this._input.charCodeAt 不是函数
【发布时间】:2016-09-14 13:10:38
【问题描述】:

我使用 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 编译器文件夹中使用,如下所示:

【问题讨论】:

  • 愿意分享您的代码吗? :P
  • 下次请正确格式化stacktrace,这样我们就不用自己动手了
  • @rinukkusu 有20多个组件的应用程序..我不这么认为..
  • @mic4ael 对不起,我添加了截图。
  • 我从来没有在我的应用程序中输入过这个,这就是为什么我不知道在这种情况下该怎么做。 @rinukkusu

标签: angular webpack angular2-cli


【解决方案1】:

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

templateUrl: 'my.component'

而不是

templateUrl: 'my.component.html'

【讨论】:

  • 刚刚过来说这拯救了我的一天。
  • 也拯救了我的一天!
【解决方案2】:

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

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

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

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

【讨论】:

  • 放在哪里?这不是很明显......
【解决方案3】:

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

将下一个 sn-p 注入到您的 ./node_modules/@angular/compiler/bundles/compiler.umd.js(或其他使用的包)中的编译器 _Tokenizer:

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

以截图为例:

【讨论】:

    猜你喜欢
    • 2018-03-07
    • 2023-04-07
    • 2021-11-21
    • 2019-02-19
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多