From e7c5dcd6da21ffc40534cd6234f117d790187666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 24 Nov 2023 14:08:40 +0100 Subject: [PATCH] MOBILE-3947 chore: Fix require.context is not a function on APP INIT --- src/core/initializers/index.ts | 12 +++++++++++- src/core/services/storage.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/initializers/index.ts b/src/core/initializers/index.ts index 993ba5d32..d9dd2a734 100644 --- a/src/core/initializers/index.ts +++ b/src/core/initializers/index.ts @@ -21,7 +21,17 @@ import { APP_INITIALIZER, Provider } from '@angular/core'; * @returns List of providers. */ export function getInitializerProviders(): Provider[] { - const context = require.context('./', false, /\.ts$/); + if (!import.meta.webpackContext) { + return []; + } + + const context = import.meta.webpackContext( + './', + { + recursive: false, + regExp: /\.\/.*\.ts$/, + }, + ); return context.keys().reduce((providers, fileName) => { const name = (fileName.match(/^(?:\.\/)?(.+)\.ts$/) || [])[1]; diff --git a/src/core/services/storage.ts b/src/core/services/storage.ts index 90e607fa3..25066f221 100644 --- a/src/core/services/storage.ts +++ b/src/core/services/storage.ts @@ -48,7 +48,7 @@ export class CoreStorageService { async initializeDatabase(): Promise { try { await CoreApp.createTablesFromSchema(APP_SCHEMA); - } catch (e) { + } catch { // Ignore errors. }