Skip to content

Babel error during localized bundle generation v9.0.0-rc.10 #16781

Closed

Description

@timofei-iatsenko

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, this is a kind of regression. I'm not sure about the root cause, it worked well in one of my previous setups with earlier RC versions. This might be as regression in AngularCli itself or because of different babel versions which I might install.

Description

An error:

Localized bundle generation failed: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,
`
babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });
`
See https://babeljs.io/docs/en/options#filename for more information.
An error occurred inlining file "main.bd935ccfc875481a7ad2.js"

The error came from packages/angular_devkit/build_angular/src/utils/process-bundle.ts:614

try {
    ast = parseSync(options.code, { // <--- Error here
      babelrc: false,
      sourceType: 'script',
    });
  } catch (error) {
    if (error.message) {
     ...
    }
  }

And obviously caused by lacking filename param.

image

A clear and concise description of the problem...

🔬 Minimal Reproduction

To reproduce just add locales into angular.json i18n.locales and turn on localize in project options

(simplified angular.json)

  {
  "projects": {
    "timescenery": {
      "i18n": {
        "locales": {
          "ru": "src/translates/messages.ru.xlf",
          "de": "src/translates/messages.de.xlf",
          "es": "src/translates/messages.es.xlf",
          "pt": "src/translates/messages.pt.xlf"
        },
        "sourceLocale": "en"
      },
      "architect": {
        "build": {
          "options": {
            "localize": true,
            "aot": true,
          },
        },
      }
    }
  }
}

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.0-rc.10
Node: 12.13.1
OS: darwin x64

Angular: 9.0.0-rc.11
... common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, upgrade
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.10
@angular-devkit/build-angular     0.900.0-rc.10
@angular-devkit/build-optimizer   0.900.0-rc.10
@angular-devkit/core              9.0.0-rc.10
@angular-devkit/schematics        9.0.0-rc.10
@angular/cdk                      9.0.0-rc.8
@angular/cli                      9.0.0-rc.10
@schematics/angular               9.0.0-rc.10
@schematics/update                0.900.0-rc.10
rxjs                              6.5.3
typescript                        3.7.2
webpack                           4.41.5

Anything else relevant?

Activity

  1. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    This might be caused by @angular/localize not pinning the Babel version?

  2. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    Can you show what version of each of the @babel/.... packages are installed?

  3. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    quote from yarn.lock

    Localize is pinning @babel/core" "^7.5.5

    image

    All @babel/core versions deduped to 7.8.3

    image

  4. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    Well, downgrading @babel/core and rest of babel packages to 7.7.2 fixes the problem, but requires some hard work to downgrade 2nd level dependencies.

    I think the issue is still actual as constatint in @angular/localize ^7.5.5 allows any 7.*.* versions including 7.8.* which is causing a crash.

  5. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    This might well be fixed by angular/angular#34974, which is currently on master and should come out in the next RC.

  6. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    This might help too angular/angular#35008

  7. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    What about adding a filename into parseSync call? Looks like bumping dependency for localize to 7.8.3 will just make this error constant for everyone, or am I wrong?

  8. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    Ah that will be a bug in @angular/devkit rather than @angular/localize. We need to fix that bug in this repo...

  9. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    Interestingly the version in build_angular is already at 7.8.3:

  10. added a commit that references this issue on Jan 28, 2020
    f7ea4d3
  11. petebacondarwin commented on Jan 28, 2020

    @petebacondarwin
    Contributor

    See #16782

  12. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    Looks like i brought clutter to this issue.
    I continued investigation with debugger and what i found.

    This error is triggered from @babel/core only in case if options.test || options.include || options.exclude is not empty.

    I checked them, and test wasn't empty. There was an
    image

    That was quite suspiciously, so I went further and found that:

    image

    Despite the fact babelrc: false, is set the babel still reads my babel.config.js placed in the root, and take presets from there, and one of the presets requires filename to be set.

    So I think problem here not only in filename property.

  13. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    I need this babel.config for my subpakages in mono-repo which use jest for testing, so this config has absolutely nothing in common with angular-cli

  14. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author

    So yes, deleting babel.config.js from root fixing the problem and proving theory that babel doesn't work in full isolation even babelrc: false is set.

    It also proves that problem not related to the version of bable.

  15. timofei-iatsenko commented on Jan 28, 2020

    @timofei-iatsenko
    Author
        ast = parseSync(options.code, { 
          babelrc: false,
          sourceType: 'script',
          configFile: false,
        });

    Adding configFile: false ensures that babel will not use any kind of configs defined in a project

  16. modified the milestone: Backlog on Jan 28, 2020
  17. added a commit that references this issue on Jan 28, 2020
    b28c125
  18. added a commit that references this issue on Jan 28, 2020
    9bbc7c7
  19. angular-automatic-lock-bot commented on Feb 28, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  20. locked and limited conversation to collaborators on Feb 28, 2020
  21. added a commit that references this issue on May 29, 2026
    f3ba669
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions