webpack import(`@angular/common/locales/${mylocale}`) not working
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
common
Is this a regression?
Yes
Description
We load our locales dynamically using a dynamic import and registerLocaleData
this works in angular 12
const localeModule = await import(
/* webpackInclude: /(sv|nb|da|fi|de|fr)/ */
/* webpackChunkName: "locale" */
`@angular/common/locales/${this.locale}.js`
)
registerLocaleData(localeModule.default)
The Problem
I found the root cause and it’s not a angular problem, but a webpack one https://github.com/webpack/webpack/issues/13865
But I though someone else might get stuck on the same thing, so I would add it as a regression.
Workaround
A workaround is to use a relative or absolute path to the node_modules folder instead
const localeModule = await import(
/* webpackInclude: /(sv|nb|da|fi|de|fr).mjs$/ */
/* webpackExports: "default" */
/* webpackChunkName: "locale" */
`node_modules/@angular/common/locales/${this.locale}`
)
registerLocaleData(localeModule.default)
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Module not found: Error: Package path ./locales is not exported from package /myrepo/node_modules/@angular/common (see exports field in /myrepo/node_modules/@angular/common/package.json)
Please provide the environment you discovered this bug in
No response
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:18
- Comments:15
Top Results From Across the Web
Angular 13 Cannot find module '@angular/common/locales/fr.js'
So basically I used to load the culture of the user by importing the locale file. const localeUri = `@angular/common/locales/${localeId}.js`; ...
Read more >Dynamic Import of Locales in Angular | by Michael Karén
Missing locale data for the locale "nb-NO". This is because your module did not import before the pipe tried to use it. Since...
Read more >Angular Internationalization
Internationalization, sometimes referenced as i18n, is the process of designing and preparing your project for use in different locales around the world.
Read more >Extending localization - IBM
You can extend the localization support in Sterling Store Engagement to support multiple locales, add languages other than the languages that are supported ......
Read more >Module Methods - webpack
It is not possible to use a fully dynamic import statement, such as import(foo) . Because foo could potentially be any path to...
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 FreeTop 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
Top GitHub Comments
It’s important to point out that using Webpack specific features such as magic comments above are not supported by the Angular tooling team. The fact that the Angular CLI is using Webpack is an implementation detail which can change in the future.
This is because dynamic imports don’t work in Webpack when an
exports
with wildcard is specified in package.jsonExample