Angular ivy i18n提取"Missing declaration for lazy-load helper function"

Angular ivy i18n extraction "Missing declaration for lazy-load helper function"

我正在尝试使用以下 cli 命令从复杂的 angular 中提取 i18n 消息:

ng extract-i18n --out-file="src/locale/messages.xlf" --format=xlf

该程序正确编译了应用程序,但在提取阶段,returns 在不同的模块和组件上出现了一堆错误,都像这样:

Error: ./src/app/path/to/mycomponent.component.ts
Module build failed (from ./node_modules/@angular-devkit/build-angular/src/extract-i18n/ivy-extract-loader.js):
Error: .../src/app/path/to/mycomponent.component.js: Missing declaration for lazy-load helper function
    at new BabelParseError (.../node_modules/@angular/localize/src/tools/src/source_file_utils.js:362:32)
    at unwrapLazyLoadHelperCall (.../node_modules/@angular/localize/src/tools/src/source_file_utils.js:254:19)
    at Object.unwrapMessagePartsFromLocalizeCall (.../node_modules/@angular/localize/src/tools/src/source_file_utils.js:127:26)
    at PluginPass.CallExpression (.../node_modules/@angular/localize/src/tools/src/extract/source_files/es5_extract_plugin.js:23:69)
    at newFn (.../node_modules/@babel/traverse/lib/visitors.js:175:21)
    at NodePath._call (.../node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (.../node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/path/context.js:92:31)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/context.js:115:16)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/context.js:121:21)
    at TraversalContext.visitSingle (.../node_modules/@babel/traverse/lib/context.js:84:19)
    at TraversalContext.visit (.../node_modules/@babel/traverse/lib/context.js:143:19)
    at Function.traverse.node (.../node_modules/@babel/traverse/lib/index.js:82:17)
    at NodePath.visit (.../node_modules/@babel/traverse/lib/path/context.js:99:18)
    at TraversalContext.visitQueue (.../node_modules/@babel/traverse/lib/context.js:115:16)
    at TraversalContext.visitSingle (.../node_modules/@babel/traverse/lib/context.js:84:19)

应用程序使用延迟加载模块,但编译和运行正确,我开始认为问题与延迟加载没有直接关系。

检查您的 babel.config.js。您很可能在项目的根文件夹中有一个。它的设置以某种方式修改了 extract-i18n 所需的结果 .js 文件。尝试删除 babel.config.js 错误将消失。