Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 15 tasks
timofei-iatsenko opened this issue Jan 28, 2020 · 15 comments · Fixed by #16782
Closed
1 of 15 tasks

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

timofei-iatsenko opened this issue Jan 28, 2020 · 15 comments · Fixed by #16782
Labels
Milestone

Comments

@timofei-iatsenko
Copy link

🐞 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?

@petebacondarwin
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

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

@timofei-iatsenko
Copy link
Author

quote from yarn.lock

Localize is pinning @babel/core" "^7.5.5

image

All @babel/core versions deduped to 7.8.3

image

@timofei-iatsenko
Copy link
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.

@petebacondarwin
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

This might help too angular/angular#35008

@timofei-iatsenko
Copy link
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?

@petebacondarwin
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

Interestingly the version in build_angular is already at 7.8.3:

petebacondarwin added a commit to petebacondarwin/angular-cli that referenced this issue Jan 28, 2020
The latest version of Babel (e.g. 7.8.3) requires a filename
to be passed to `parseSync()`.

Fixes angular#16781
@petebacondarwin
Copy link
Contributor

See #16782

@timofei-iatsenko
Copy link
Author

timofei-iatsenko commented Jan 28, 2020

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.

@timofei-iatsenko
Copy link
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

@timofei-iatsenko
Copy link
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.

@timofei-iatsenko
Copy link
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

@ngbot ngbot bot modified the milestone: Backlog Jan 28, 2020
@alan-agius4 alan-agius4 modified the milestones: Backlog, v9-candidates Jan 28, 2020
kyliau pushed a commit that referenced this issue Jan 28, 2020
The latest version of Babel (e.g. 7.8.3) requires a filename
to be passed to `parseSync()`.

Fixes #16781
kyliau pushed a commit that referenced this issue Jan 28, 2020
The latest version of Babel (e.g. 7.8.3) requires a filename
to be passed to `parseSync()`.

Fixes #16781
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants