From b8ffa3a2da65b7fadfb0dbea5aeb543687bbfecc Mon Sep 17 00:00:00 2001 From: sommeeeR <91796856+sommeeeer@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:18:26 +0200 Subject: [PATCH] add check for config and config.default (#464) * Add check for config.default being undefined * Add check for both config and config.default * Create eighty-masks-cheat.md --------- Co-authored-by: conico974 --- .changeset/eighty-masks-cheat.md | 5 +++++ docs/pages/config.mdx | 10 +++++++++- packages/open-next/src/build.ts | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/eighty-masks-cheat.md diff --git a/.changeset/eighty-masks-cheat.md b/.changeset/eighty-masks-cheat.md new file mode 100644 index 00000000..051df174 --- /dev/null +++ b/.changeset/eighty-masks-cheat.md @@ -0,0 +1,5 @@ +--- +"open-next": patch +--- + +add check for config and config.default diff --git a/docs/pages/config.mdx b/docs/pages/config.mdx index b300b6a1..644e9bcb 100644 --- a/docs/pages/config.mdx +++ b/docs/pages/config.mdx @@ -7,10 +7,18 @@ There is two build arguments that you can pass to the `open-next build` command: ### Configuration File -For personalisation you need to create a file `open-next.config.ts` at the same place as your `next.config.js`, and export a default object that satisfies the `OpenNextConfig` interface. +For personalisation you need to create a file `open-next.config.ts` at the same place as your `next.config.js`, and export a default object that satisfies the `OpenNextConfig` interface. It is possible to not have an `open-next.config.ts` file, the default configuration will then be applied automatically. This file needs to be placed at the same level as your `next.config.js` file. +If you have an `open-next.config.ts` file, make sure you have atleast this: + +```ts +export default { + default: {}, +}; +``` + If you want to take a look at some simple configuration examples, you can check the [simple example](/config/simple_example). For more advanced use cases, you can check [how to implement custom overrides](/config/custom_overrides). diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts index f0f30d03..8108b7b4 100755 --- a/packages/open-next/src/build.ts +++ b/packages/open-next/src/build.ts @@ -58,6 +58,12 @@ export async function build( // On Windows, we need to use file:// protocol to load the config file using import() if (process.platform === "win32") configPath = `file://${configPath}`; config = (await import(configPath)).default as OpenNextConfig; + if (!config || !config.default) { + logger.error( + `config.default cannot be empty, it should be at least {}, see more info here: https://open-next.js.org/config#configuration-file`, + ); + process.exit(1); + } validateConfig(config); compileOpenNextConfigEdge(tempDir, config, openNextConfigPath);