Skip to content

Commit

Permalink
Add next.config.js validation with ajv (#38498)
Browse files Browse the repository at this point in the history
* Add next.config.js validation with ajv

* update manifest

* update lib type

* remove old tests

* update to pre-build validation code

* ensure validate output is ncced

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

* Add example of typing next.config.js

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
ijjk and styfle committed Jul 13, 2022
1 parent 5a15c5f commit 62f3f87
Show file tree
Hide file tree
Showing 12 changed files with 782 additions and 74 deletions.
24 changes: 24 additions & 0 deletions errors/invalid-next-config.md
@@ -0,0 +1,24 @@
# Invalid next.config.js

#### Why This Error Occurred

In your `next.config.js` file you passed invalid options that either are the incorrect type or an unknown field.

#### Possible Ways to Fix It

Fixing the listed config errors will remove this warning. You can also leverage the `NextConfig` type by importing from `next` to help ensure your config is correct.

```ts
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
}

module.exports = nextConfig
```

### Useful Links

- [`next.config.js`](https://nextjs.org/docs/api-reference/next.config.js/introduction)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -711,6 +711,10 @@
{
"title": "node-module-in-edge-runtime",
"path": "/errors/node-module-in-edge-runtime.md"
},
{
"title": "invalid-next-config",
"path": "/errors/invalid-next-config.md"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/index.d.ts
@@ -1,4 +1,5 @@
/// <reference types="./types/global" />
/// <reference path="./dist/styled-jsx-types/global.d.ts" />
/// <reference path="./amp.d.ts" />
/// <reference path="./app.d.ts" />
/// <reference path="./config.d.ts" />
Expand All @@ -11,7 +12,6 @@
/// <reference path="./router.d.ts" />
/// <reference path="./script.d.ts" />
/// <reference path="./server.d.ts" />
/// <reference path="./dist/styled-jsx-types/global" />

export { default } from './types'
export * from './types'
2 changes: 2 additions & 0 deletions packages/next/package.json
Expand Up @@ -50,6 +50,7 @@
"index.d.ts",
"types/index.d.ts",
"types/global.d.ts",
"types/compiled.d.ts",
"image-types/global.d.ts"
],
"bin": {
Expand Down Expand Up @@ -168,6 +169,7 @@
"@vercel/ncc": "0.33.4",
"@vercel/nft": "0.20.0",
"acorn": "8.5.0",
"ajv": "8.11.0",
"amphtml-validator": "1.0.35",
"arg": "4.1.0",
"assert": "2.0.0",
Expand Down

0 comments on commit 62f3f87

Please sign in to comment.