Skip to content

Commit

Permalink
chore: throw error when trying to use next.config.mts/.cjs/.cts (not …
Browse files Browse the repository at this point in the history
…supported yet) (#70376)

## Why?

We should update our documentation and also throw an error if somebody
tries to use the `.mts` ( ES Module TypeScript) extension with
`next.config`. We currently don't support this extension.

- Fixes: #70201

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
samcx and ijjk committed Sep 24, 2024
1 parent aa445d5 commit ac9a514
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/02-app/02-api-reference/05-next-config-js/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const nextConfig = {
export default nextConfig
```

> **Good to know**: `next.config` with the `.cjs`, `.cts`, or `.mts` extensions are currently **not** supported.
## Configuration as a Function

You can also use a function:
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,9 +1178,12 @@ export default async function loadConfig(
const configBaseName = basename(CONFIG_FILES[0], extname(CONFIG_FILES[0]))
const unsupportedConfig = findUp.sync(
[
`${configBaseName}.cjs`,
`${configBaseName}.cts`,
`${configBaseName}.mts`,
`${configBaseName}.json`,
`${configBaseName}.jsx`,
`${configBaseName}.tsx`,
`${configBaseName}.json`,
],
{ cwd: dir }
)
Expand Down

0 comments on commit ac9a514

Please sign in to comment.