From 4675a36ef58ea2f878766e24bd95746a566c6671 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:38:34 -0800 Subject: [PATCH] fix: do not use safe require for vercel deployments --- app/i18next.server.ts | 3 +++ app/utils/platform-adapter.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/i18next.server.ts b/app/i18next.server.ts index a05e6e58..52762671 100644 --- a/app/i18next.server.ts +++ b/app/i18next.server.ts @@ -4,6 +4,7 @@ import i18n from '~/i18n'; // your i18n configuration file import HttpBackend from 'i18next-http-backend'; import { IS_CF_PAGES, + IS_VERCEL, safeRequireNodeDependency, } from '~/utils/platform-adapter'; import { RemixI18NextOption } from 'remix-i18next/build/server'; @@ -13,6 +14,8 @@ import { findLanguageJSON } from '~/languages.server'; export async function getPlatformBackend() { if (IS_CF_PAGES) { return HttpBackend; + } else if (IS_VERCEL) { + return await import('i18next-fs-backend').then((module) => module.default); } else { return await safeRequireNodeDependency('i18next-fs-backend').then( (module) => module.default, diff --git a/app/utils/platform-adapter.ts b/app/utils/platform-adapter.ts index acb0b7bf..e0a368bb 100644 --- a/app/utils/platform-adapter.ts +++ b/app/utils/platform-adapter.ts @@ -1,5 +1,7 @@ export const IS_CF_PAGES = typeof process === 'undefined'; +export const IS_VERCEL = 'VERCEL' in process.env; + // This hack is to prevent `node` modules/packages being bundled in the // Cloudflare Pages context, which causes an error. export async function safeRequireNodeDependency(module: string) {