Search code examples
angular-cliangular-i18nangular-ivy

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


I'm trying to extract i18n messages from a complex angular using the following cli command:

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

The procedure compile correctly the application but, in the extraction phase, returns a bunch of errors on different module and components, all like this:

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)

The application uses lazy-loaded modules, but compiles and runs correctly and I'm starting to think the issue is not directly related with the lazy-loading.


Solution

  • Check your babel.config.js. Most likely you have one in the root folder of your project. Its settings somehow amend resulting .js files needed for extract-i18n. Try to remove babel.config.js and the error will disappear.