Angular i18n and Server Side Rendering LOCALE_DATA is not populated
See original GitHub issueVersions
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 1.7.3
Node: 8.9.4
OS: win32 x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
@angular/cli: 1.7.3
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
Repro steps
- Create new project CLI
- Follow the Universal guides at https://github.com/angular/angular-cli/wiki/stories-universal-rendering
- Build universal server for fr-FR locale
"build:client-and-server-bundles": "ng build --prod --locale=fr-FR && ng build --locale=fr-FR --app 1 --output-hashing=false"
I have put this in a minimal repo which reproduces the problem:
git clone https://github.com/martinmcwhorter/ssr-i18n-missing-locales.git
cd ssr-i18n-missing-locales
npm install
npm run build:ssr
npm run serve:ssr
Observed behavior
In the console where npm run server:ssr was run:
ERROR Error: Missing locale data for the locale "fr-FR".
at findLocaleData (D:\projects\ssr-i18n-missing-locales\dist\server.js:29460:11)
at getLocaleId (D:\projects\ssr-i18n-missing-locales\dist\server.js:29069:12)
at getNamedFormat (D:\projects\ssr-i18n-missing-locales\dist\server.js:31664:37)
at formatDate (D:\projects\ssr-i18n-missing-locales\dist\server.js:31625:40)
at DatePipe.transform (D:\projects\ssr-i18n-missing-locales\dist\server.js:32415:16)
at checkAndUpdatePureExpressionInline (D:\projects\ssr-i18n-missing-locales\dist\server.js:14760:38)
at checkAndUpdateNodeInline (D:\projects\ssr-i18n-missing-locales\dist\server.js:15476:20)
at checkAndUpdateNode (D:\projects\ssr-i18n-missing-locales\dist\server.js:15415:16)
at prodCheckAndUpdateNode (D:\projects\ssr-i18n-missing-locales\dist\server.js:16139:5)
at Object.updateRenderer (D:\projects\ssr-i18n-missing-locales\dist\server.js:134994:7131)
View Source of the pre-rendered HTML is missing the interpolations that use the i18n pipe.
If you run with the default ‘en’ locale data you will not see these two issues:
npm run build:ssr:en
npm run serve:ssr
Desired behavior
At https://angular.io/guide/i18n#i18n-pipes states
"The CLI imports the locale data for you when you use the parameter --locale with ng serve and ng build."
I would expect that the fr-FR locale be imported into the server bundles built with the --locale=fr-FR argument.
Mention any other details that might be useful (optional)
Opened a ticket at the Angular repo, @ocombe suggested opening a ticket here. https://github.com/angular/angular/issues/22793
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Angular i18n and Server Side Rendering LOCALE_DATA ...
When I rerun the above for English, I get no error for the server missing locale data, and the i18n pipes render the...
Read more >Angular Universal SSR with i18n not loading locale from ...
The server is likely serving the static file first by default. To get around that you should change the name of index.html to ......
Read more >Import global variants of the locale data
Import global variants of the locale datalink ... The Angular CLI automatically includes locale data if you run the ng build command with...
Read more >Server-side rendering (SSR) with Angular Universal
Easily prepare an application for server-side rendering using the Angular CLI. ... The files marked with * are new and not in the...
Read more >Set the runtime locale manually
The Angular CLI automatically includes the locale data and sets the LOCALE_ID value when you use the --localize option with ng build command....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a workaround for this issue.
In your server.ts add:
In your webpack.server.config.js add
Just want to follow up that this is still and issue with angular cli 6 – though the workaround still works.