I have recently updated my Angular application to V12. I am using Angular's own Internationalization library @angular/localize
. I am using webpack's raw-loader
to load the xlf translation files as a string in my main.ts using the following code
const locale = document['locale'] as string;
const translations = require(`raw-loader!./assets/locale/messages.${locale}.xlf`).default;
platformBrowserDynamic().bootstrapModule(AppModule, {
providers: [
{ provide: TRANSLATIONS, useValue: translations },
{ provide: LOCALE_ID, useValue: locale },
{ provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
]
});
After the update I get the following error Error: Module not found: Error: Can't resolve 'raw-loader'
What could be the reason for this? Is there any way other than raw-loader?
I had that issue migrating the angular version ,and i've solved it installing it with
npm install raw-loader --save-dev
. It is because angular 12 now uses webpack5. If you don't solve the problem try to change const translations = require(raw-loader!./assets/locale/messages.${locale}.xlf
).default; to an ES import dynamic declaration like in your case that you use a variable ${locale} inside it, maybe you can take a look at this post ES6 variable import name in node.js? . and use !!raw-loader... instead of raw-loader