From 5f8add038c30d87ec402cafa58e41b16af3c502a Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 13:54:55 -0800 Subject: [PATCH 1/9] fix: vercel no route convention --- remix.config.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/remix.config.js b/remix.config.js index ceca95ec..14ee2945 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,4 +1,4 @@ -import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; +// import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; /** * @type {import('@remix-run/dev').AppConfig} @@ -11,7 +11,7 @@ const bareConfig = { tailwind: true, routes(defineRoutes) { // uses the v1 convention, works in v1.15+ and v2 - return createRoutesFromFolders(defineRoutes); + // return createRoutesFromFolders(defineRoutes); }, }; @@ -85,5 +85,4 @@ function selectConfig() { throw new Error(`Cannot select config`); } -// export default selectConfig(); -module.exports = selectConfig(); +export default selectConfig(); From 8e91e0f6820d0620b1b74e23c4ecdef299abfab7 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:03:41 -0800 Subject: [PATCH 2/9] fix: more config tweaks for vercel --- remix.config.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/remix.config.js b/remix.config.js index 14ee2945..64c08886 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,4 +1,4 @@ -// import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; +import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; /** * @type {import('@remix-run/dev').AppConfig} @@ -9,9 +9,12 @@ const bareConfig = { '@remix-validated-form/with-zod', ], tailwind: true, +}; + +const routesConfig = { routes(defineRoutes) { // uses the v1 convention, works in v1.15+ and v2 - // return createRoutesFromFolders(defineRoutes); + return createRoutesFromFolders(defineRoutes); }, }; @@ -22,6 +25,7 @@ const commonConfig = { appDirectory: 'app', serverModuleFormat: 'esm', ...bareConfig, + ...routesConfig, }; /** @@ -40,6 +44,7 @@ const cloudflarePagesConfig = { */ const vercelConfig = { ignoredRouteFiles: ['**/.*'], + ...bareConfig, }; /** * @type {import('@remix-run/dev').AppConfig} From e60691f4b905ab38ace2387275272e0ec112dccb Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:07:01 -0800 Subject: [PATCH 3/9] fix: one more tweak --- remix.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/remix.config.js b/remix.config.js index 64c08886..5b6e13e4 100644 --- a/remix.config.js +++ b/remix.config.js @@ -6,6 +6,7 @@ import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; const bareConfig = { serverDependenciesToBundle: [ 'remix-i18next', + 'i18next-fs-backend', '@remix-validated-form/with-zod', ], tailwind: true, From d13bb0c411ef00603c48ef8fd89535a72a6da2a7 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:20:37 -0800 Subject: [PATCH 4/9] chore: something is off --- remix.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/remix.config.js b/remix.config.js index 5b6e13e4..64c08886 100644 --- a/remix.config.js +++ b/remix.config.js @@ -6,7 +6,6 @@ import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; const bareConfig = { serverDependenciesToBundle: [ 'remix-i18next', - 'i18next-fs-backend', '@remix-validated-form/with-zod', ], tailwind: true, From ffc60550a1fa1f5fd737c1922725b6a56d919950 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:23:55 -0800 Subject: [PATCH 5/9] fix: use bare import --- app/i18next.server.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/i18next.server.ts b/app/i18next.server.ts index a05e6e58..f88b010c 100644 --- a/app/i18next.server.ts +++ b/app/i18next.server.ts @@ -14,9 +14,7 @@ export async function getPlatformBackend() { if (IS_CF_PAGES) { return HttpBackend; } else { - return await safeRequireNodeDependency('i18next-fs-backend').then( - (module) => module.default, - ); + return await import('i18next-fs-backend').then((module) => module.default); } } From 0b59bd8e54e60f9f8c8f3c316590894dc5bd1ed1 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:27:52 -0800 Subject: [PATCH 6/9] chore: no route convention import --- remix.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remix.config.js b/remix.config.js index 64c08886..83b1f99d 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,4 +1,4 @@ -import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; +// import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; /** * @type {import('@remix-run/dev').AppConfig} @@ -14,7 +14,7 @@ const bareConfig = { const routesConfig = { routes(defineRoutes) { // uses the v1 convention, works in v1.15+ and v2 - return createRoutesFromFolders(defineRoutes); + // return createRoutesFromFolders(defineRoutes); }, }; From 2fb6d14d5e016d7a4ff6eefa9edf6a4e76d1f052 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:29:57 -0800 Subject: [PATCH 7/9] chore: add routes config for vercel deploy --- remix.config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/remix.config.js b/remix.config.js index 83b1f99d..a5e06931 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,4 +1,4 @@ -// import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; +import { createRoutesFromFolders } from '@remix-run/v1-route-convention'; /** * @type {import('@remix-run/dev').AppConfig} @@ -14,7 +14,7 @@ const bareConfig = { const routesConfig = { routes(defineRoutes) { // uses the v1 convention, works in v1.15+ and v2 - // return createRoutesFromFolders(defineRoutes); + return createRoutesFromFolders(defineRoutes); }, }; @@ -45,6 +45,7 @@ const cloudflarePagesConfig = { const vercelConfig = { ignoredRouteFiles: ['**/.*'], ...bareConfig, + ...routesConfig, }; /** * @type {import('@remix-run/dev').AppConfig} From 7b7fefa7e8ec1cde82f393759ec70611b4fbad0f Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:33:21 -0800 Subject: [PATCH 8/9] chore: use safe require --- app/i18next.server.ts | 4 +++- remix.config.js | 5 ----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/i18next.server.ts b/app/i18next.server.ts index f88b010c..a05e6e58 100644 --- a/app/i18next.server.ts +++ b/app/i18next.server.ts @@ -14,7 +14,9 @@ export async function getPlatformBackend() { if (IS_CF_PAGES) { return HttpBackend; } else { - return await import('i18next-fs-backend').then((module) => module.default); + return await safeRequireNodeDependency('i18next-fs-backend').then( + (module) => module.default, + ); } } diff --git a/remix.config.js b/remix.config.js index a5e06931..b807b5ae 100644 --- a/remix.config.js +++ b/remix.config.js @@ -9,9 +9,6 @@ const bareConfig = { '@remix-validated-form/with-zod', ], tailwind: true, -}; - -const routesConfig = { routes(defineRoutes) { // uses the v1 convention, works in v1.15+ and v2 return createRoutesFromFolders(defineRoutes); @@ -25,7 +22,6 @@ const commonConfig = { appDirectory: 'app', serverModuleFormat: 'esm', ...bareConfig, - ...routesConfig, }; /** @@ -45,7 +41,6 @@ const cloudflarePagesConfig = { const vercelConfig = { ignoredRouteFiles: ['**/.*'], ...bareConfig, - ...routesConfig, }; /** * @type {import('@remix-run/dev').AppConfig} From 4675a36ef58ea2f878766e24bd95746a566c6671 Mon Sep 17 00:00:00 2001 From: dmi3y Date: Fri, 8 Mar 2024 14:38:34 -0800 Subject: [PATCH 9/9] 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) {