Skip to content

Commit

Permalink
feat(remix-dev): add warning for v2 "cjs"->"esm" defaults (#6154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Apr 24, 2023
1 parent 3709710 commit 8a74add
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cjs-esm-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

add warning for v2 "cjs"->"esm" serverModuleFormat default change
6 changes: 6 additions & 0 deletions docs/pages/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions integration/hmr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let fixture = (options: {
files: {
"remix.config.js": js`
module.exports = {
serverModuleFormat: "cjs",
tailwind: true,
future: {
unstable_dev: {
Expand Down
3 changes: 3 additions & 0 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
flatRoutesWarning,
formMethodWarning,
metaWarning,
serverModuleFormatWarning,
} from "../config";

beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
Expand Down Expand Up @@ -359,6 +360,8 @@ describe("the create command", () => {
"\n" +
metaWarning +
"\n" +
serverModuleFormatWarning +
"\n" +
flatRoutesWarning +
"\n\n" +
getOptOutOfInstallMessage() +
Expand Down
11 changes: 11 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,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) {
Expand Down Expand Up @@ -895,6 +900,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. " +
Expand Down

0 comments on commit 8a74add

Please sign in to comment.