Repository navigation
Babel error during localized bundle generation v9.0.0-rc.10 #16781
Copy link
Copy link
Closed
Labels
area: @angular-devkit/build-angularfreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity3: brokentype: bug/fix
Milestone
Description
🐞 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.
🔬 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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: @angular-devkit/build-angularfreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity3: brokentype: bug/fix

Activity
petebacondarwin commentedon Jan 28, 2020
This might be caused by
@angular/localizenot pinning the Babel version?petebacondarwin commentedon Jan 28, 2020
Can you show what version of each of the
@babel/....packages are installed?timofei-iatsenko commentedon Jan 28, 2020
quote from
yarn.lockLocalize is pinning
@babel/core" "^7.5.5All
@babel/coreversions deduped to 7.8.3timofei-iatsenko commentedon Jan 28, 2020
Well, downgrading
@babel/coreand rest of babel packages to7.7.2fixes 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 any7.*.*versions including7.8.*which is causing a crash.petebacondarwin commentedon Jan 28, 2020
This might well be fixed by angular/angular#34974, which is currently on master and should come out in the next RC.
petebacondarwin commentedon Jan 28, 2020
This might help too angular/angular#35008
timofei-iatsenko commentedon Jan 28, 2020
What about adding a
filenameintoparseSynccall? Looks like bumping dependency forlocalizeto7.8.3will just make this error constant for everyone, or am I wrong?petebacondarwin commentedon Jan 28, 2020
Ah that will be a bug in
@angular/devkitrather than@angular/localize. We need to fix that bug in this repo...petebacondarwin commentedon Jan 28, 2020
Interestingly the version in
build_angularis already at 7.8.3:angular-cli/packages/angular_devkit/build_angular/package.json
Line 14 in ca7973e
fix(@angular-devkit/build-angular): pass filename to `parseSync`
petebacondarwin commentedon Jan 28, 2020
See #16782
timofei-iatsenko commentedon 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/coreonly in case ifoptions.test || options.include || options.excludeis not empty.I checked them, and

testwasn't empty. There was anThat was quite suspiciously, so I went further and found that:
Despite the fact
babelrc: false,is set the babel still reads mybabel.config.jsplaced 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
filenameproperty.timofei-iatsenko commentedon Jan 28, 2020
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 commentedon Jan 28, 2020
So yes, deleting
babel.config.jsfrom root fixing the problem and proving theory that babel doesn't work in full isolation evenbabelrc: falseis set.It also proves that problem not related to the version of bable.
timofei-iatsenko commentedon Jan 28, 2020
Adding
configFile: falseensures that babel will not use any kind of configs defined in a projectfix(@angular-devkit/build-angular): pass filename to `parseSync`
fix(@angular-devkit/build-angular): pass filename to `parseSync`
angular-automatic-lock-bot commentedon Feb 28, 2020
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.
fix(@angular-devkit/build-angular): pass filename to `parseSync`