From 87565d414c9946c112744fdb176f044ce35e44a0 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Mon, 24 Apr 2023 11:19:32 -0700 Subject: [PATCH 1/3] feat: add warning for v2 "cjs"->"esm" defaults --- docs/pages/v2.md | 6 ++++++ packages/remix-dev/__tests__/create-test.ts | 3 +++ packages/remix-dev/config.ts | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/docs/pages/v2.md b/docs/pages/v2.md index dd59b44ef77..5d1351426ae 100644 --- a/docs/pages/v2.md +++ b/docs/pages/v2.md @@ -689,6 +689,12 @@ module.exports = { }; ``` +## `serverModuleFormat` + +The default server module output format will be changing from `cjs` to `esm`. + +In your `remix.config.js`, you should specify either `serverModuleFormat: "cjs"` to retain existing behavior, or `serverModuleFormat: "esm"`, to opt into the future behavior. + ## Dev Server We are still stabilizing the new dev server that enables HMR, several CSS libraries (CSS Modules, Vanilla Extract, Tailwind, PostCSS) and simplifies integration with various servers. diff --git a/packages/remix-dev/__tests__/create-test.ts b/packages/remix-dev/__tests__/create-test.ts index 9640bcaff1a..3891972938f 100644 --- a/packages/remix-dev/__tests__/create-test.ts +++ b/packages/remix-dev/__tests__/create-test.ts @@ -13,6 +13,7 @@ import { flatRoutesWarning, formMethodWarning, metaWarning, + serverModuleFormatWarning, } from "../config"; beforeAll(() => server.listen({ onUnhandledRequest: "error" })); @@ -359,6 +360,8 @@ describe("the create command", () => { "\n" + metaWarning + "\n" + + serverModuleFormatWarning + + "\n" + flatRoutesWarning + "\n\n" + getOptOutOfInstallMessage() + diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 8b4a0a0fec6..80c885eadbd 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -453,6 +453,11 @@ export async function readConfig( let serverEntryPoint = appConfig.server; let serverMainFields = appConfig.serverMainFields; let serverMinify = appConfig.serverMinify; + + if (!appConfig.serverModuleFormat) { + warnOnce(serverModuleFormatWarning, "serverModuleFormatWarning") + } + let serverModuleFormat = appConfig.serverModuleFormat || "cjs"; let serverPlatform = appConfig.serverPlatform || "node"; if (isCloudflareRuntime) { @@ -893,6 +898,12 @@ export let serverBuildTargetWarning = "For instructions on making this change see " + "https://remix.run/docs/en/v1.15.0/pages/v2#serverbuildtarget"; +export const serverModuleFormatWarning = + "⚠️ REMIX FUTURE CHANGE: The `serverModuleFormat` config default option will be changing in v2 " + + "from `cjs` to `esm`. You can prepare for this change by explicitly specifying `serverModuleFormat: 'cjs'`. " + + "For instructions on making this change see " + + "https://remix.run/docs/en/v1.16.0/pages/v2#servermoduleformat"; + export let flatRoutesWarning = "⚠️ REMIX FUTURE CHANGE: The route file convention is changing in v2. " + "You can prepare for this change at your convenience with the `v2_routeConvention` future flag. " + From 295cde304eb1586cef910c617204fdbb2bfa0470 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Mon, 24 Apr 2023 11:21:23 -0700 Subject: [PATCH 2/3] add changeset --- .changeset/cjs-esm-warning.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cjs-esm-warning.md diff --git a/.changeset/cjs-esm-warning.md b/.changeset/cjs-esm-warning.md new file mode 100644 index 00000000000..404c2f4b754 --- /dev/null +++ b/.changeset/cjs-esm-warning.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +add warning for v2 "cjs"->"esm" serverModuleFormat default change From 3291fc86f3139df75867fac7d81387f459b98387 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Mon, 24 Apr 2023 13:54:01 -0700 Subject: [PATCH 3/3] update HRM test to include serverModuleFormat to silence warning and allow test to succeed --- integration/hmr-test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/hmr-test.ts b/integration/hmr-test.ts index 61858c787cc..d0c78af8cc6 100644 --- a/integration/hmr-test.ts +++ b/integration/hmr-test.ts @@ -11,6 +11,7 @@ let fixture = (options: { port: number; appServerPort: number }) => ({ files: { "remix.config.js": js` module.exports = { + serverModuleFormat: "cjs", tailwind: true, future: { unstable_dev: {