diff --git a/.changeset/afraid-peaches-accept.md b/.changeset/afraid-peaches-accept.md new file mode 100644 index 00000000000..8774b45b891 --- /dev/null +++ b/.changeset/afraid-peaches-accept.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +Add support for .mjs and .cjs remix.config files. diff --git a/examples/blog-tutorial/package.json b/examples/blog-tutorial/package.json index bc1787f31df..c970016f2c5 100644 --- a/examples/blog-tutorial/package.json +++ b/examples/blog-tutorial/package.json @@ -46,7 +46,7 @@ "@testing-library/cypress": "^8.0.2", "@testing-library/dom": "^8.13.0", "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^13.3.0", + "@testing-library/react": "^12.1.5", "@testing-library/user-event": "^13.5.0", "@types/eslint": "^8.4.1", "@types/marked": "^4.0.3", diff --git a/packages/remix-dev/cli/run.ts b/packages/remix-dev/cli/run.ts index fac58a39778..868d4071a69 100644 --- a/packages/remix-dev/cli/run.ts +++ b/packages/remix-dev/cli/run.ts @@ -332,7 +332,8 @@ export async function run(argv: string[] = process.argv.slice(2)) { }, message: "Which Stack do you want? ", loop: false, - suffix: "(Learn more about these stacks: https://remix.run/stacks)", + suffix: + "(Learn more about these stacks: 'https://remix.run/stacks')", choices: [ { name: "Blues", diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 72927be1a5f..0ac1ce51893 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -287,15 +287,18 @@ export async function readConfig( } let rootDirectory = path.resolve(remixRoot); - let configFile = path.resolve(rootDirectory, "remix.config.js"); - - let appConfig: AppConfig; - try { - appConfig = require(configFile); - } catch (error) { - throw new Error( - `Error loading Remix config in ${configFile}\n${String(error)}` - ); + let configFile = findConfig(rootDirectory, "remix.config"); + + let appConfig: AppConfig = {}; + if (configFile) { + try { + let appConfigModule = await import(configFile); + appConfig = appConfigModule?.default || appConfig; + } catch (error) { + throw new Error( + `Error loading Remix config at ${configFile}\n${String(error)}` + ); + } } let customServerEntryPoint = appConfig.server; @@ -475,3 +478,14 @@ function findEntry(dir: string, basename: string): string | undefined { return undefined; } + +const configExts = [".js", ".cjs", ".mjs"]; + +function findConfig(dir: string, basename: string): string | undefined { + for (let ext of configExts) { + let file = path.resolve(dir, basename + ext); + if (fse.existsSync(file)) return file; + } + + return undefined; +}