Skip to content

Commit

Permalink
add check for config and config.default (#464)
Browse files Browse the repository at this point in the history
* Add check for config.default being undefined

* Add check for both config and config.default

* Create eighty-masks-cheat.md

---------

Co-authored-by: conico974 <[email protected]>
  • Loading branch information
sommeeeer and conico974 authored Jul 8, 2024
1 parent 7beaf82 commit b8ffa3a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eighty-masks-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

add check for config and config.default
10 changes: 9 additions & 1 deletion docs/pages/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 6 additions & 0 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b8ffa3a

Please sign in to comment.