Commit graph

517 commits

Author SHA1 Message Date
Steven
4cc7f11da2
Update to stable: next/future/image, remotePatterns, unoptimized (#40142)
This PR updates a few features from experimental to stable status:

- `next/future/image` component
- `remotePatterns` configuration
- `unoptimized` configuration
2022-08-31 22:44:17 +00:00
Jerome Leclanche
a799d25cfa
Mention largePageDataBytes in warning docs (#39941)
Also fix the KB unit to `kB` (https://en.wikipedia.org/wiki/Kilobyte)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-08-25 10:52:32 -05:00
Sukka
5360440413
fix(#39609): warns about suspense and ssr (#39676)
Currently, `next/dynamic` will opt-in to `React.lazy` if `{ suspense: true }` is used. And React 18 will always resolve the `Suspense` boundary on the server-side, effectively ignoring the `ssr` option.

The PR fixes #39609 by showing a warning message when `{ suspense: true, ssr: false }` is detected. The error documentation and the corresponding test case has also been updated.

In the future, Next.js could implement a custom version of `React.lazy` that could suspense without executing the lazy-loaded component on the server-side.

cc @huozhi 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-08-18 13:53:23 +00:00
M. Zakiyuddin Munziri
5f033ecb54
Fix docs path "Invalid getServerSideProps Return Value" (#39443)
# Description

The link to https://nextjs.org/docs/messages/invalid-getserversideprops-value does not exist, the correct link should be https://nextjs.org/docs/messages/invalid-getserversideprops-return-value

![image](https://user-images.githubusercontent.com/78015359/183795431-53210024-4938-4f50-9f0a-cb412383780e.png)

![image](https://user-images.githubusercontent.com/78015359/183795482-f17f31c2-cbaf-4652-ad77-5294fa8f104a.png)

# Solution

## From

Referring to the pattern, there is no `return`

![Screenshot from 2022-08-10 10-04-33](https://user-images.githubusercontent.com/78015359/183795393-ba244d6a-84b3-426c-b5ef-4e17d108902a.png)

## To

So I removed the word `return` to match the pattern

![image](https://user-images.githubusercontent.com/78015359/183796280-da6f10d1-c017-4075-942a-01d9ad234c27.png)


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-08-10 02:34:43 +00:00
Lee Robinson
5d93753bc3
API Routes Request Helpers docs. (#39407)
Renames Middleware to Request Helpers to be both more accurate and also less confusing since Middleware is a separate feature of Next.js now.
2022-08-09 02:02:14 +00:00
Balázs Orbán
b292bdc293
fix(ts): Middleware type tweaks (#38625)
* fix internal type

* allow `void` to be returned from Middleware

* mark deprecated APIs in JSDoc

* fix typo

* add missing error page

* remove unused import
2022-08-08 09:40:44 -05:00
Josh Goldberg
963585a4fc
fix: improve logging for _devPagesManifest.json loading failures (#38046)
## Bug

- [x] Fixes #38047
- ~[ ] Integration tests added: do you want them added for such an unusual edge case?~ [Comment below: skipping](https://github.com/vercel/next.js/pull/38046#issuecomment-1207444526)
- [x] Errors have helpful link attached, see `contributing.md`: ~I'll wait until this approach & error message are confirmed before thinking more deeply on how to explain the error~

Sending a draft PR as reference ahead of time. 🙂 

Doesn't resolve the root issue of why `_devPagesManifest.json` might fail to load. But does improve the log for when it happens. I'd suggest applying this same fix to `_devMiddlewareManifest.json` too.

<table>
<thead>
<tr>
<th></th>
<th>Before</th>
<th>After</th>
</tr>
</thead>
<tbody>
<tr>
<th>Console</th>
<td>
<pre>
<code>
Failed to fetch devPagesManifest TypeError: Failed to fetch
    at PageLoader.getPageList (page-loader.js?e87a:30:53)
    at _callee$ (router.js?8684:955:45)
    at ...
</code>
</pre>
<pre>
<code>
router.js?8684:1319 Uncaught (in promise) TypeError: Cannot \
read properties of undefined (reading 'includes')
    at resolveDynamicRoute (router.js?8684:1319:16)
    at _callee$
    at ...
</code>
</pre>
</td>
<td>
<pre>
<code>
Failed to fetch devPagesManifest: TypeError: Failed to fetch
    at PageLoader.getPageList (page-loader.js?e87a:30:53)
    at _callee$ (router.js?8684:955:45)
    at ...
</code>
</pre>
</td>
</tr>
<tr>
<th>Visual</th>
<td><img alt="Screenshot of a Next.js runtime error: TypeError: Cannot read properties of undefined (reading 'includes')" src="https://user-images.githubusercontent.com/3335181/175854728-8d5c2051-1229-4da7-8af1-fc95236befae.png" /></td>
<td><img alt="Screenshot of a Next.js runtime error: Error: Failed to fetch _devPagesManifest.json. Is something blocking that network request?" src="https://user-images.githubusercontent.com/3335181/175854774-07895846-1a1c-4bb8-bf57-fa696b8c6ba4.png" /></td>
</tr>
</tbody>
</table>
2022-08-07 19:36:03 +00:00
Sukka
02c78a5c15
fix(#38743): config.runtime support template literal (#38750)
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #38743.
Fixes: https://github.com/vercel/next.js/pull/38750

The PR adds basic `TemplateLiteral` support for static analysis.

The corresponding re-production of #38743 has also been implemented in e2e tests.
2022-07-21 19:56:52 +00:00
Lee Robinson
5d4ac47f7a
Improve response body in Middleware error page. (#38537)
* Improve respond body in Middleware error page.

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-18 20:20:23 -05:00
JJ Kasper
62f3f87891
Add next.config.js validation with ajv (#38498)
* 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>
2022-07-13 13:31:55 -05:00
Damien Simonin Feugas
6e2c3821cf
feat: build edge functions with node.js modules and fail at runtime (#38234)
## What's in there?

The Edge runtime [does not support Node.js modules](https://edge-runtime.vercel.app/features/available-apis#unsupported-apis).
When building Next.js application, we currently fail the build when detecting node.js module imported from middleware.

This is an blocker for using code that is conditionally loading node.js modules (based on platform/env detection), as @cramforce reported.

This PR implements a new strategy where:
- we can build such middleware/Edge API route code **with a warning**
- we fail at run time, with graceful errors in dev (console & react-dev-overlay error)
- we fail at run time, with console errors in production

## How to test?

All cases are covered with integration tests.
To try them live, create a simple app with a page, a `middleware.js` file and a `pages/api/route.js`file.
Here are iconic examples:

### node.js modules
```js
// middleware.js
import { NextResponse } from 'next/server'
// static
import { basename } from 'path'

export default async function middleware() {
  // dynamic
  const { basename } = await import('path')
  basename()
  return NextResponse.next()
}

export const config = { matcher: '/' }
```
```js
// pags/api/route.js
// static
import { isAbsolute } from 'path'

export default async function handle() {
  // dynamic
  const { isAbsolute } = await import('path')
  return Response.json({ useNodeModule: isAbsolute('/test') })
}

export const config = { runtime: 'experimental-edge' }
```

Desired error (+ source code highlight in dev):

> The edge runtime does not support Node.js 'path' module
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

Desired warning at build time:

> A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

- [x]  in dev middleware, static, shows desired error on stderr
- [x]  in dev route, static, shows desired error on stderr
- [x]  in dev middleware, dynamic, shows desired error on stderr
- [x]  in dev route, dynamic, shows desired error on stderr
- [x]  in dev middleware, static, shows desired error on react error overlay
- [x]  in dev route, static, shows desired error on react error overlay
- [x]  in dev middleware, dynamic, shows desired error on react error overlay
- [x]  in dev route, dynamic, shows desired error on react error overlay
- [x]  builds middleware successfully, shows build warning, shows desired error on stderr on call
- [x]  builds route successfully, shows build warning, shows desired error on stderr on call

### 3rd party modules not found

```js
// middleware.js
import { NextResponse } from 'next/server'
// static
import Unknown from 'unknown'

export default async function middleware() {
  // dynamic
  const Unknown = await import('unknown')
  new Unknown()
  return NextResponse.next()
}
```
export const config = { matcher: '/' }
```
```js
// pags/api/route.js
// static
import Unknown from 'unknown'

export default async function handle() {
  // dynamic
  const Unknown = await import('unknown')
  return Response.json({ use3rdPartyModule: Unknown() })
}

export const config = { runtime: 'experimental-edge' }
```

Desired error (+ source code highlight in dev):

> Module not found: Can't resolve 'does-not-exist'
Learn More: https://nextjs.org/docs/messages/module-not-found

- [x]  in dev middleware, static, shows desired error on stderr
- [x]  in dev route, static, shows desired error on stderr
- [x]  in dev middleware, dynamic, shows desired error on stderr
- [x]  in dev route, dynamic, shows desired error on stderr
- [x]  in dev middleware, static, shows desired error on react error overlay
- [x]  in dev route, static, shows desired error on react error overlay
- [x]  in dev middleware, dynamic, shows desired error on react error overlay
- [x]  in dev route, dynamic, shows desired error on react error overlay
- [x]  fails to build middleware, with desired error on stderr
- [x]  fails to build route, with desired error on stderr

### unused node.js modules
```js
// middleware.js
import { NextResponse } from 'next/server'

export default async function middleware() {
  if (process.exit) {
    const { basename } = await import('path')
    basename()
  }
  return NextResponse.next()
}
```
```js
// pags/api/route.js
export default async function handle() {
  if (process.exit) {
    const { basename } = await import('path')
    basename()
  }
  return Response.json({ useNodeModule: false })
}

export const config = { runtime: 'experimental-edge' }
```

Desired warning at build time:

> A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

- [x]  invoke middleware in dev with no error
- [x]  invoke route in dev with no error
- [x]  builds successfully, shows build warning, invoke middleware with no error
- [x]  builds successfully, shows build warning, invoke api-route with no error

## Notes to reviewers

The strategy to implement this feature is to leverages webpack [externals](https://webpack.js.org/configuration/externals/#externals) and run a global `__unsupported_module()` function when using a node.js module from edge function's code.
For the record, I tried using [webpack resolve.fallback](https://webpack.js.org/configuration/resolve/#resolvefallback) and [Webpack.IgnorePlugin](https://webpack.js.org/plugins/ignore-plugin/) but they do not allow throwing proper errors at runtime that would contain the loaded module name for reporting.

`__unsupported_module()` is defined in `EdgeRuntime`, and returns a proxy that's throw on use (whether it's property access, function call, new operator... synchronous & promise-based styles).

However there's an issue with error reporting: webpack does not includes the import lines in the generated sourcemaps, preventing from displaying useful errors.
I extended our middleware-plugin to supplement the sourcemaps (when analyzing edge function code, it saves which module is imported from which file, together with line/column/source)

The react-dev-overlay was adapted to look for this additional information when the caught error relates to modules, instead of looking at sourcemaps.

I removed the previous mechanism (built by @nkzawa ) which caught webpack errors at built time to change the displayed error message (files `next/build/index.js`, `next/build/utils.ts` and `wellknown-errors-plugin`)
2022-07-06 20:54:44 +00:00
Emerson Laurentino
6b8e499c7b
fix: middleware-upgrade-guide.md (#38246)
* Update middleware-upgrade-guide.md

* Update middleware-upgrade-guide.md
2022-07-01 22:24:34 -05:00
Michael Novotny
c83f94cf8b
Readds missing @next/next/no-assign-module-variable ESLint rule. (#38134)
Readds `@next/next/no-assign-module-variable` ESLint rule that was inadvertently removed in #34335 during the resolution of many merge conflicts.

This PR will get us back to a good / working state. I'll see if I can add a test to ensure all rule are accounted for in a separate PR.

Fixes #34335.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-29 02:54:47 +00:00
Edward Thomson
dd1492d3a0
Update middleware upgrade guide w/ more rationale (#38074)
* Update middleware upgrade guide w/ more rationale

The API changes for GA are general improvements.

Our middleware upgrade guide is very helpful about describing the changes
that were made and how to react to them; include some additional "why" to
rationalize these changes.

* Update middleware-upgrade-guide.md

Avoid words like "simple" and "easy"

* Update middleware-upgrade-guide.md

Clarify the issues around "security" with responses - the previous verbiage made it sound like there was a security vulnerability; there was not.

* Apply suggestions from code review

Co-authored-by: Lee Robinson <me@leerob.io>

* Apply suggestions from code review

* Update errors/middleware-upgrade-guide.md

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* Apply suggestions from code review

* Update canary -> latest

* Apply suggestions from code review

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-28 10:31:47 -05:00
JJ Kasper
8e161e1855
Middleware docs update (#38111)
* Initial outline added for middleware docs

* Feedback changes - not included new user agent yet

* edge api routes docs

* middleware page some cleanup

* moved api stuff to next server, added useragent

* waitUntil example added

* Updated env vars section

* Added cookies on the request object example

* fixed naming

* fixed import typo

* Amy feedback

* Update docs/advanced-features/middleware.md

Co-authored-by: Amy Burns <amy.burns@vercel.com>

* first commit

* more fixes

* re-structuring based on feedback

* changes to middleware.md

* updates to edge-api-routes

* code typo

* Update docs/advanced-features/middleware.md

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Update edge-api-routes.md

* Update Edge Runtime API docs

* Clarify API docs

* Update

* Update docs/advanced-features/middleware.md

* Update switchable runtime docs

* Update response

* experimental-edge

* Update docs/advanced-features/middleware.md

* Add example of forwarding headers and address comments

* Add proxying headers to middleware upgrade guide

* Apply suggestions from code review

Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com>

* fix middleware directory spec

* localization explanation

* update detecting runtime

* Update docs/advanced-features/react-18/switchable-runtime.md

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* fix prettier issues

* table fix

* Update docs/advanced-features/react-18/switchable-runtime.md

Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com>

* Update docs/api-routes/edge-api-routes.md

Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com>

* lint-fix

Co-authored-by: molebox <hello@richardhaines.dev>
Co-authored-by: Amy Burns <amy.burns@vercel.com>
Co-authored-by: Ismael Rumzan <ismael.rumzan@gmail.com>
Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com>
Co-authored-by: Ismael <ismael@vercel.com>
2022-06-28 10:22:48 -05:00
Dom Sip
a90349d519
Update middleware-upgrade-guide to be consistent (#38102)
Update middleware-upgrade-guide.md

Ensure that before and after examples are consistent
2022-06-28 14:48:57 +02:00
Javi Velasco
0f33c0cbf5
Rephrase middleware location (#38073)
It is possible that users that are defining `src/pages` in their project confuse the "project root" to locate middleware with the actual project root instead of `src/middleware` so this PR rephrases the migration guide to make explicit that the it should be located **next** to the `pages` folder.
2022-06-27 17:13:19 +00:00
Steven Tey
8019cf002a
Added ESLint upgrade instructions to middleware upgrade guide (#38008)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-27 00:20:36 +00:00
M. Zakiyuddin Munziri
2833904b6f
Fix typo for rewrites/redirects to rewrite/redirect (#38016)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-26 16:17:34 -05:00
Lee Robinson
5646e43f83
Fix typo for rewrites to rewrite. (#38000) 2022-06-24 15:45:02 -05:00
Balázs Orbán
a590c4e7f3
docs: return response in code example (#37985)
* Update middleware-upgrade-guide.md

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-24 11:13:40 -05:00
Steven
e28d03c5a4
Add experimental next/future/image component (#37927)
This PR introduces a new experimental component, `next/future/image`, which is inspired by the existing experimental `layout="raw"`.

The difference is that much of the code has been deleted in order to reduce client-side code as well as reduce complexity:

- No `layout` prop
- No `loader` config (although `loader` prop works)
- No `IntersectionObserver`, use native `loading="lazy"` 
  - No `lazyBoundary`
  - No `lazyRoot`
- No `fill` (yet) so width & height are required
- No `objectFit` (use `style` instead)
- No `objectPosition` (use `style` instead)

This improves performance because native `loading="lazy"` doesn't need to wait for React Hydration and client-side JS.

In a future PR, we will modify `next/image` to remove `layout="raw"` since this new component supersedes it.

## Feature

- [x] Integration tests added
- [x] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`
2022-06-24 14:56:05 +00:00
Lee Robinson
b0533635ab
Update Middleware beta message. (#37934)
To help folks find the upgrade guide.
2022-06-23 01:11:31 +00:00
Lee Robinson
f3c1bcfc2f
Change Middleware error guide from .js to .ts. (#37858)
Feedback:

> Hello :D may it be that the types should be imported in a TS file, so I think the extension of the file should be updated here :) /middleware.js -> /middleware.ts (or no types)
2022-06-20 21:56:19 +00:00
Lee Robinson
c84c7c8c3e
Fix broken link for no-script-in-document-page error. (#37831)
Going to https://nextjs.org/docs/messages/no-script-in-document-page incorrectly redirects to https://nextjs.org/errors/no-script-in-document.
2022-06-19 20:26:52 +00:00
Lee Robinson
c480726da2
Update 4MB API Routes warning error guide. (#37779)
We added documentation for this, but didn't post it back to the error guide, which is linked when you'd hit this limit.

https://github.com/vercel/next.js/pull/34700
2022-06-16 21:59:54 +00:00
Steven
b7d057453d
Add images.unoptimized: true for easy next export (#37698)
In a previous PR (#19032), we added a hard error during `next export` if the default Image Optimization API is being used because it requires a server to optimized on demand. The error message offers several different solutions but it didn't consider that by the time someone runs `next export`, they are probably done writing their app.

So if `next export` is a hard requirement, the quickest path forward is to disable Image Optimization API. So this PR adds a new configuration option to `next.config.js`:

```js
module.exports = {
  images: {
    unoptimized: true
  }
}
```

### Update
Upon further discussion, we might want to avoid doing this just for images and instead introduce a top-level config to indicate export is coming and then handle errors or warn for [unsupported features](https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features).

```
module.exports = {
  nextExport: true
}
```

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-16 20:20:17 +00:00
Robert Cunningham
87a3c0c5bd
fix grammar in failed-loading-swc (#37765)
just a little clearer, was confused previously
2022-06-16 14:38:42 -05:00
JJ Kasper
97395b4cd6
Add missing error manifest entry and fix lint (#37758)
* Add missing error manifest entry

* fix lint

* guid -> guide
2022-06-16 11:46:15 -05:00
Lee Robinson
eb55af1cfe
Add upgrade guide for Middleware. (#37382)
* Middleware upgrade guide

* Add a bit more

* Apply suggestions from code review

Co-authored-by: Rich Haines <hello@richardhaines.dev>
Co-authored-by: Edward Thomson <ethomson@github.com>
Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com>

* Apply suggestions from code review

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Updates based on PR comments

* Add before / after

* Flip paragraphs

* Apply suggestions from code review

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Apply suggestions from code review

Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com>

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com>

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com>

* Update middleware-upgrade-guide.md

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Apply suggestions from code review

Co-authored-by: Rich Haines <hello@richardhaines.dev>

* Apply suggestions from code review

* Update errors/middleware-upgrade-guide.md

Co-authored-by: Rich Haines <hello@richardhaines.dev>
Co-authored-by: Edward Thomson <ethomson@github.com>
Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com>
Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com>
Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com>
Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 09:29:18 -07:00
Seiya Nuta
0bf9233e14
[middleware] Warn dynamic WASM compilation (#37681)
In Middlewares, dynamic code execution is not allowed. Currently, we warn if eval / new Function are invoked in dev but don't warn another dynamic code execution in WebAssembly.

This PR adds warnings for `WebAssembly.compile` and `WebAssembly.instantiate` with a buffer parameter (note that `WebAssembly.instantiate` with a **module** parameter is legit) invocations. Note that other methods that compile WASM dynamically such as `WebAssembly.compileStreaming` are not exposed to users so we don't need to cover them.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-16 14:59:30 +00:00
Andrei Stefan
6b829d8bd6
fix(eslint): allow <img> in conjunction with <picture> (#37504) (#37570)
* fix(eslint): allow <img> in conjunction with <picture> (#37504)

* Apply suggestions from code review

* add space

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-15 21:13:52 -05:00
Michael Novotny
5211ac5cae
Adds consistency to ESLint rules. (#34335)
* Adds consistency to ESLint rules.

* Fixes lint errors.

* Fixes manifest.

* Adds missing title.

* Fixes copy / paste error.

Co-authored-by: Lee Robinson <me@leerob.io>

* Update errors/no-script-in-document.md

Co-authored-by: Lee Robinson <me@leerob.io>

* Update errors/no-sync-scripts.md

Co-authored-by: Lee Robinson <me@leerob.io>

* Updates a couple of rule descriptions.

* Adds redirects.

* Fixes unit tests.

* Removes duplicated section.

* Updates `no-before-interactive-script-outside-document` description.

* Fixes lint.

* Fixes integration tests.

* Adds description to `no-before-interactive-script-outside-document` documentation.

* Removes `link-passhref` from rules list.

* Updates remaining `pages/_middleware.js` references.

* Adds consistancy to messaging in new `no-styled-jsx-in-document` rule.

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-13 21:17:42 -05:00
Splatterxl
e0631d0ef1
Fix links in google-font-display error (#37661) 2022-06-13 10:17:36 -05:00
Houssein Djirdeh
2eb48e7837
[Script] Updates stale no-script-in-document-page error doc (#37568)
[Recent changes](https://github.com/vercel/next.js/pull/31936) to `next/script` introduced the capability to use `beforeInteractive` scripts in the custom document. This old error message is incorrect.
2022-06-13 03:04:15 +00:00
Joe Previte
6108f10799
feat(next export): add warning if using getInitialProps (#37642)
This PR builds on the work from @hattakdev (PR went stale: https://github.com/vercel/next.js/pull/14499) and adds a new `integration` test for the new warning.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

![image](https://user-images.githubusercontent.com/3806031/173214117-f5159f3a-778c-4177-894d-78e7bb0c80e7.png)

## To run locally
1. `pnpm build` 
2. `pnpm testonly test/integration/export-getInitialProps-warn/test/index.test.js`

Fixes #13946

## Notes

<details>
<summary>Click to toggle see</summary>

I know the `contributing.md` doc said to avoid adding new tests to `integration`. It also said new tests should be written in TypeScript.

I wasn't sure where to put the tests for this so I went with `integration`. I also didn't see many other tests written in TS in this part of the codebase so I stuck with `.js`. 

</details>

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-13 02:34:23 +00:00
Kiko Beats
76083210ed
Middleware: remove req.ua (#37512)
This PR moves the internal logic associated with `req.ua` into an explicit method the user should to call to have the same behavior.

**before**

```typescript
// middleware.ts
import { NextRequest, NextResponse } from 'next/server'
export function middleware(request: NextRequest) {
  const url = request.nextUrl
  const viewport = request.ua.device.type === 'mobile' ? 'mobile' : 'desktop'
  url.searchParams.set('viewport', viewport)
  return NextResponse.rewrites(url)
}
```

**after**

```typescript
// middleware.ts
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function middleware(request: NextRequest) {
  const url = request.nextUrl
  const { device } = userAgent(request)
  const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'
  url.searchParams.set('viewport', viewport)
  return NextResponse.rewrites(url)
}
```

This potentially will save the extra 17 kB related to the size of `ua-parser-js`
2022-06-09 11:10:21 +00:00
Kiko Beats
129052dc98
Edge Functions: deprecate access to request.page (#37349)
It uses `URLSearchParams` to have the same behavior.

closes https://github.com/vercel/next.js/issues/34521
2022-06-01 20:06:37 +00:00
Lee Robinson
1f47d0b34b
Update nested Middleware error reference (#37368) 2022-06-01 10:09:11 -05:00
Jiachi Liu
c984281f90
docs: fix usage in middleware errors (#37364)
## Documentation

- [x] Make sure the linting passes by running `pnpm lint`
2022-06-01 12:03:07 +00:00
Dilwoar Hussain
1cd34dd640
Use appropriate className attribute for JSX (#37168)
## What

This changes the` class` attribute with `className`

## Why

Class is a reserved word in JavaScript. The appropriate attribute to use is `className`.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-05-24 23:15:06 +00:00
Alexandru Tasica
e4bf1a515c
Docs: missing parenthesis on example (#37156)
Missing close parenthesis on docs example from page custom-document-image-import.md

## Bug

- [x] Related issues linked using `fixes #37155`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-24 15:01:56 +00:00
Sharath Challa
11ad65e445
Add eslint rule for not allowing styled-jsx in _document.js (#32678)
## Bug

- [ ] Related issues linked
fixes #32656



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-23 02:32:13 +00:00
Hannes Bornö
318664562c
next-swc: Improve error message for nested styled jsx tags (#33805)
Before
![image](https://user-images.githubusercontent.com/25056922/151694166-a27a35b6-5fb4-4179-8c88-bd98ede35fea.png)

After
![image](https://user-images.githubusercontent.com/25056922/151758033-65576e5b-e2e8-435d-87b3-9e384b13936b.png)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-22 22:45:58 +00:00
Damien Simonin Feugas
bf089562c7
feat(middleware)!: forbids middleware response body (#36835)
_Hello Next.js team! First PR here, I hope I've followed the right practices._

### What's in there?

It has been decided to only support the following uses cases in Next.js' middleware:
- rewrite the URL (`x-middleware-rewrite` response header)
- redirect to another URL (`Location` response header)
- pass on to the next piece in the request pipeline (`x-middleware-next` response header)

1. during development, a warning on console tells developers when they are returning a response (either with `Response` or `NextResponse`).
2. at build time, this warning becomes an error.
3. at run time, returning a response body will trigger a 500 HTTP error with a JSON payload containing the detailed error.

All returned/thrown errors contain a link to the documentation.

This is a breaking feature compared to the _beta_ middleware implementation, and also removes `NextResponse.json()` which makes no sense any more.

### How to try it?
- runtime behavior: `HEADLESS=true yarn jest test/integration/middleware/core`
- build behavior : `yarn jest test/integration/middleware/build-errors`
- development behavior: `HEADLESS=true yarn jest test/development/middleware-warnings`

### Notes to reviewers

The limitation happens in next's web adapter. ~The initial implementation was to check `response.body` existence, but it turns out [`Response.redirect()`](https://github.com/vercel/next.js/blob/canary/packages/next/server/web/spec-compliant/response.ts#L42-L53) may set the response body (https://github.com/vercel/next.js/pull/31886). Hence why the proposed implementation specifically looks at response headers.~
`Response.redirect()` and `NextResponse.redirect()` do not need to include the final location in their body: it is handled by next server https://github.com/vercel/next.js/blob/canary/packages/next/server/next-server.ts#L1142

Because this is a breaking change, I had to adjust several tests cases, previously returning JSON/stream/text bodies. When relevant, these middlewares are returning data using response headers.

About DevEx: relying on AST analysis to detect forbidden use cases is not as good as running the code.
Such cases are easy to detect:
```js
new Response('a text value')
new Response(JSON.stringify({ /* whatever */ })
```
But these are false-positive cases:
```js
function returnNull() { return null }
new Response(returnNull())

function doesNothing() {}
new Response(doesNothing())
```
However, I see no good reasons to let users ship middleware such as the one above, hence why the build will fail, even if _technically speaking_, they are not setting the response body. 



## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-19 22:02:20 +00:00
Javi Velasco
f354f46b3f
Deprecate nested Middleware in favor of root middleware (#36772)
This PR deprecates declaring a middleware under `pages` in favour of the project root naming it after `middleware` instead of `_middleware`. This is in the context of having a simpler execution model for middleware and also ships some refactor work. There is a ton of a code to be simplified after this deprecation but I think it is best to do it progressively.

With this PR, when in development, we will **fail** whenever we find a nested middleware but we do **not** include it in the compiler so if the project is using it, it will no longer work. For production we will **fail** too so it will not be possible to build and deploy a deprecated middleware. The error points to a page that should also be reviewed as part of **documentation**.

Aside from the deprecation, this migrates all middleware tests to work with a single middleware. It also splits tests into multiple folders to make them easier to isolate and work with. Finally it ships some small code refactor and simplifications.
2022-05-19 15:46:21 +00:00
Jiachi Liu
ed4d009841
Drop the unstable web vital hook and remove exports of flush effects (#36912)
* remove the experimental web vital hook api
* remove the exported flush effects api and only error on development, keep only usage to styled-jsx

for web vital hook API: The usage is not widly adopted since the existing exported vital api could do the same work. In the future we'll deprecate the `_app.server` in favor of `_app` in server component pages. so that this api won't be required.

for flush effects api: other css-in-js libs are not using the same approach like styled-jsx which holding a style registry and could flush it during streaming. emotion-js and styled-components are still relying on `Document.getInitialProps` atm and we have supported it in latest canary
2022-05-14 21:20:24 +00:00
Hunter Tunnicliff
521f88e159
Move CI build cache instructions to Deployment docs (#35418)
This PR moves the instructions for configuring CI providers to preserve Next.js's build cache out of the _No Cache Detected_ error message and into ~the _Deployment_~ a new page within the _Advanced Features_ docs. 

This change is beneficial because it makes the CI configuration examples visible in the context of other helpful documentation for deploying Next.js.

👉 **Prior to this change, these CI configuration examples didn't show up in the Next.js docs.**

The relocated instructions are now linked on the _No Cache Detected_ error message page.

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Steven <steven@ceriously.com>
2022-05-13 09:56:47 -04:00
Erik Brinkman
c7b2083f2e
Add experimental flag to force SWC transforms (#36789)
fixes #36763
fixes #36590

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
   - It hasn't been accepted for implementation, although that process isn't clear, and this is a pretty trivial fix.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
   - This is somewhat inherent in the error log
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-10 10:33:31 +00:00
Steven
da8d1984d2
Add experimental wildcard remotePatterns config for upstream images (#36245)
## Description 
This PR implements a new configuration object in `next.config.js` called `experimental.images.remotePatterns`.

This will eventually deprecate `images.domains` because it covers the same use cases and more by allowing wildcard pattern matching on `hostname` and `pathname` and also allows restricting `protocol` and `port`.

## Feature

- [x] Implements an existing feature request.
- [x] Related issues linked
- [x] Unit tests added
- [x] Integration tests added
- [x] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Related 

- Fixes #27925 
- Closes #18429 
- Closes #18632
- Closes #18730
- Closes #27345
2022-05-05 02:19:16 +00:00
LongYinan
2012f4e7c6
Update components in GitHub Actions (#36669)
`build-native` jobs tested on https://github.com/vercel/next.js/runs/6288266017
2022-05-04 18:51:25 +00:00
Houssein Djirdeh
fd2ba11763
Adds inline script functionality to next/script for worker and beforeInteractive strategies (#36364)
Adds inline script functionality to `next/script` for `worker` and `beforeInteractive` strategies. 

- fixes #36318 
- fixes #26343
- fixes #26591
- fixes #26343
- fixes #26240


Co-authored-by: Janicklas Ralph <6142074+janicklas-ralph@users.noreply.github.com>
2022-04-29 15:20:31 +00:00
JJ Kasper
4f5c2deb4c
Add note about lockfile causing swc to fail to load (#36484)
* Add note about lockfile causing swc to fail to load

* Apply suggestions from code review

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
2022-04-26 14:48:52 -05:00
Jiachi Liu
d5e767b20d
Add process env NEXT_RUNTIME (#36383)
* To help determine the current running environment is in server nodejs / edge runtime
* Remove usage of `process.browser`
2022-04-26 17:54:28 +00:00
Maedah Batool
60488e68e3
Fix broken data fetching links in docs (#33766)
* Fix broken links for Data Fetching

* Fix link data fetching doc

* Improve link file paths

* Update errors/large-page-data.md

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

* Update links

* Fix linting

* Lint tests

* Lint tests

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2022-04-22 14:03:07 +02:00
Janicklas Ralph
0441f816a6
Changes to the beforeInteractive strategy to make it work for streaming (#31936)
Changes to the beforeInteractive strategy to make it work for streaming

Splitting `beforeInteractive` into two strategies `beforeInteractive` at the _document level and `beforePageRender` for page level <Scripts>
2022-04-21 21:15:53 +00:00
Michael Ward
1be5f36123
Adds linting rule to avoid assignment to 'module' variable. Fixes #34859 (#35279) 2022-04-15 14:45:53 +02:00
Vlad Tansky
a11479bad9
docs: failed-loading-swc possible fix for Windows users (#36081)
Apparently, Microsoft Visual C++ Redistributable is required for Windows users. 

> The issue is because the package is failing due to a missing library on the computer. fs-search requires Microsoft Visual C++ 2015 Redistributable (x64).
> You can get the download here -> https://aka.ms/vs/17/release/vc_redist.x64.exe

from https://stackoverflow.com/questions/69859120/the-specified-module-could-not-be-found-d-next-js-firstapp-node-modules-n



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-04-12 18:21:11 +00:00
Samuel
cb565d69cf
Update: Add appropriate error message when for getServerSideProps invalid return value (#35887) 2022-04-06 10:25:27 -05:00
Samuel
739e6f0760
Docs: Add useful link to invalid-getstaticprops-value error message (#35915)
## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

I would like to add useful link to `getStaticProps` invalid return value error message as currently there is no useful link being provided. I believe that this might improve the developer experience.
2022-04-05 18:59:58 +00:00
JJ Kasper
b1a7b88890
Add warning when importing "next" directly (#35884)
* Add warning when importing "next" directly

* Apply suggestions from code review

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* Apply suggestions from code review

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

* add example

Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Steven <steven@ceriously.com>
2022-04-05 10:57:45 -05:00
Jon Espen Kvisler
127bbc0ba6
Update dead link for getStaticPaths in docs (#35814) 2022-04-01 11:51:18 +02:00
Jiachi Liu
27d23f5b7b
docs: update styling support for streaming (#35375)
## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-03-26 20:19:21 +00:00
JJ Kasper
72478c5c80
Update next/link error when no children are provided (#35453)
* Update next/link error when no children are provided

* update manifest

* Apply suggestions from code review

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-03-22 13:58:55 -05:00
Sacha
b579a35e83
[examples] Update styled-components to use SWC (#34770)
* rename example with-styled-components to with-styled-components-babel

* update with-styled-components references

* update docs on react hydratation erros for styled components

* clone with-styled-components-babel without babel config

* add styledComponents to compiler options in next.config

* replace babel dependency with Next.js SWC compiler

* upgrade example typescript version

example with-typescript-styled-components had a typescript dependency
lower than the recommended version. Upgraded from 4.2.4 to 4.5.5.

* Apply suggestions from code review

* update readme for with-styled-components-babel

remove Notes section since it describes a workaround which is no longer
required to work with `next/link`.

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-03-02 03:43:34 +01:00
JJ Kasper
35a1af4cf4
Add redirect for error doc rename (#34791) 2022-02-25 11:09:04 -08:00
Colin Rice
079b507327
Add API config to allow disabling response size warning (#34700)
Adds an API config option that disables warning a user when their API response body is over 4 megs. This has been added for users who'd like to stream larger amounts of data from their API acknowledging the drawbacks. This config mirrors the existing [`externalResolver` config](https://nextjs.org/docs/api-routes/api-middlewares#custom-config).

Closes: [#33162](https://github.com/vercel/next.js/issues/33162)

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-25 02:04:02 +00:00
mxgnus
7d98537f95
added styled-components & replay support in swc (#34647)
styled-components & relay is supported in swc since nextjs 12.1
2022-02-21 12:28:38 -06:00
Lionel
4ad1c5a2bc
Update wrong code snippet (#34520)
Following the [example](https://nextjs.org/docs/advanced-features/custom-document), avoiding the following error:
>  Identifier 'Document' has already been declared



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-18 10:03:27 +00:00
Gerald Monaco
944c734d04
Add unstable_useFlushEffects hook (#34117)
Implements https://github.com/vercel/next.js/issues/30997 with some minor tweaks to the design:

* The hook is moved to Client Components (e.g. `pages/_app` instead of `pages/_document`). This was a silly oversight in the original design: the hook needs to be called during server prerendering.

* `useFlushEffects` instead of `useFlushEffect` as there isn't a particularly safe way to implement the singular semantics as a Client Component hook given the current implementation of server rendering.

---

Fixes #30997
2022-02-18 00:18:28 +00:00
JJ Kasper
d4eea7593a
Fix snippet language sh -> bash (#34487) 2022-02-17 11:05:40 -06:00
Gal Schlezinger
f0f322c0d1
Remove deprecation for relative URL usage in middlewares (#34461)
* Remove deprecation for relative URL usage in middlewares

* fix tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-17 09:12:36 -06:00
Steven
8a55612c0d
Add image config for dangerouslyAllowSVG and contentSecurityPolicy (#34431)
## Feature

- [x] Integration tests added
- [x] Documentation added
- [x] Errors have helpful link attached, see `contributing.md`



Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2022-02-16 19:28:22 +00:00
Balázs Orbán
d88793d973
feat: improve opening a new issue flow (#34434)
Ref: [Slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1645003443213449)

When opening a new issue, it is desired that the user has checked if the `canary` release not already have fixed their issue, since we do not backport fixes to previous Next.js versions.

- added a CLI warning when `next info` runs that looks like this:

![image](https://user-images.githubusercontent.com/18369201/154309275-01ccc979-01e5-4ccb-8a22-5deab64765a0.png)

This links to a message docs page with more information and some useful links.

- refactored our bug report templates to be more clear and removed the fields that are now unnecessary (since running `next info` is expected to run on releases that already have it)

- Made browser/deployment optional, as in most cases those fields are irrelevant. We still ask them, but mention that they are only needed if relevant.

- Asking for the exact browser version now

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-16 17:45:01 +00:00
Rich Haines
127f94dc13
Updated failed to load error page to include info about node versions (#34362)
This PR updates the [failed loading swc](https://nextjs.org/docs/messages/failed-loading-swc) error page with information about switching node version and installing deps again.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-15 15:44:10 +00:00
Ben Ilegbodu
41ecd5e6e2
docs: Add link to pageExtensions config in page-without-valid-component.md (#34285)
The [Page Without Valid React Component](https://nextjs.org/docs/messages/page-without-valid-component) explains some ways to fix the problem of Next finding a non-React Component. However, if someone is trying to use `.mdx` as an extension, or wants to include tests, stories or other non-page files in their `pages` folder there's nothing for them.

The [Custom Page Extensions](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) has all the info to help them out, but adding it to this error page should make it more discoverable.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-02-14 17:25:45 +00:00
Hassan El Mghari
ca8530ffc8
Changed all occurrences of etc to match (#34280)
The [correct](https://www.grammarly.com/blog/et-cetera-etc/) way to use et cetera is to put a period right after and a comma behind it if it's being used as a list. I updated the occurrences in the docs and examples that didn't match these rules.
2022-02-13 00:22:52 +00:00
Hassan El Mghari
26c40f3186
Add heading to invalid-api-status-body error (#34150) 2022-02-09 21:01:58 -06:00
Maia Teegarden
01ee7e0b22
Chore/stable swc compiler options (#34074)
Mark some previously experimental swc compiler options as stable under a new `compiler` option

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-10 01:54:28 +00:00
Tim Neutkens
c74e4f21ff
Add support for async fn / promise in next.config.js/.mjs (#33662)
- Add support for async function / promise export in next.config.js/.mjs
- Update docs

Adds support for https://twitter.com/timneutkens/status/1486075973204422665

But also the simpler version:

```js
module.exports = async () => {
  return {
    basePath: '/docs'
  }
}
```



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-07 08:48:35 +00:00
Chris Patterson
74a65332a4
Changing GitHub Actions cache documentation (#28228)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-06 19:01:38 +00:00
Lakshya Thakur
8039c6b2b5
fix: Change url to nextUrl inside delete-query-params-in-middlewares.md (#33796)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-06 09:21:28 -06:00
Krychaxp
3055a82ede
Add note about dns-prefetch as fallback (#30385)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-06 02:53:26 +00:00
Kara
24fe279751
Warn in dev mode when stylesheets are added using next/head (#34004)
This commit adds a development mode warning in the console
if you try to include <link rel="stylesheet"> tags in
next/head, e.g.

```
<Head>
  <link ref="stylesheet" href="..." />
</Head>
```

The warning message explains that this pattern will not
work well with Suspense/streaming and recommends using a
custom Document component instead.

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-04 22:48:30 +00:00
Jiachi Liu
4812e22992
docs: use function for components in general (#33990) 2022-02-04 09:18:35 -06:00
Kara
61ea8efe42
Warn in dev mode when script tags are added with next/head (#33968)
This commit adds a development mode warning in the console
if you try to include <script> tags in next/head, e.g.

```
<Head>
  <script async src="..." />
</Head>
```

The warning message explains that this pattern will not
work well with Suspense/streaming and recommends using the
next/script component instead.

TODO in follow-up PR: add same warning for stylesheets, etc

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Integration tests added
- [x] Documentation added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-04 13:06:55 +00:00
Balázs Orbán
b7725133f8
docs: recommend .end instead of .send when no body is being sent (#33611)
Fixes #33536

I was thinking to make `body` optional here instead:

2c6bd1ed1b/packages/next/shared/lib/utils.ts (L262)

But that might result in more errors when not setting the status code correctly. So it's the easiest for us to just recommend `.end()` which `.send()` uses when there is no argument.

c71465d87a/packages/next/server/api-utils.ts (L269)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-03 02:41:28 +00:00
Rich Haines
138361208c
Fixed duplicate data fetching overview page + links (#33774)
This PR removes the duplicate overview link for data fetching, and fixes the corresponding links

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-01-29 02:52:40 +00:00
Gal Schlezinger
7b2ea48745
Allow to delete URL search params in middleware rewrites (#33725)
This allows to have a more streamlined API for rewrites.
Since middlewares are code and not static configurations, we can allow people to
delete query params and not just overwrite them.

**⚠️ Warning ⚠️** this is a breaking change in query parameter behavior with middlewares, but the API will make more sense now. Compare the following:

```diff
  import {NextResponse} from 'next/server'
  export default function middleware({ nextUrl }) {
-   nextUrl.searchParams.set('ignored-query-param', '');
+   nextUrl.searchParams.delete('ignored-query-param'); // 🎉
    return NextResponse.rewrite(nextUrl);
  }
```

Since this is breaking change, we're adding a warning every time we find a query param that is missing, and eventually--the warning will be deleted.
I don't think we need to worry about older versions of Next.js as the current behavior is misleading: merging query parameters make sense for static rewrites, but not for middlewares where you have access to all the query parameters and can manipulate them freely.

Related:
* This is the opposite of #33454
* This supersedes #33574
2022-01-27 22:06:39 +00:00
Karl Horky
5c6c385100
Use relative path for example (#33565)
The paths starting with slashes in the ESLint config examples are absolute, which are almost never the correct configuration for a project. Using a relative path is a much more common configuration, and leads to much less debugging why these examples don't work.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-01-26 12:41:14 +00:00
Baoshuo Ren
72658c918a
fix(errors/no-cache): netlify-plugin-cache-nextjs has been deprecated (#33629) 2022-01-25 14:59:32 +01:00
Javi Velasco
e5dee17f77
Enforce absolute URLs in Edge Functions runtime (#33410)
We currently have inconsistencies when working with URLs in the Edge Functions runtime, this PR addresses them introducing a warning for inconsistent usage that will break in the future. Here is the reasoning.

### The Browser

When we are in a browser environment there is a fixed location stored at `globalThis.location`. Then, if one tries to build a request with a relative URL it will work using that location global hostname as _base_ to construct its URL. For example:

```typescript
// https://nextjs.org
new Request('/test').url; // https://nextjs.org/test
Response.redirect('/test').headers.get('Location'); // https://nextjs.org/test
```

However, if we attempt to run the same code from `about:blank` it would not work because the global to use as a base `String(globalThis.location)` is not a valid URL. Therefore a call to `Response.redirect('/test')` or `new Response('/test')` would fail.

### Edge Functions Runtime

In Next.js Edge Functions runtime the situation is slightly different from a browser. Say that we have a root middleware (`pages/_middleware`) that gets invoked for every page. In the middleware file we expose the handler function and also define a global variable that we mutate on every request:

```typescript
// pages/_middleware

let count = 0;

export function middleware(req: NextRequest) {
  console.log(req.url);
  count += 1;
}
```

Currently we cache the module scope in the runtime so subsequent invocations would hold the same globals and the module would not be evaluated again. This would make the counter to increment for each request that the middleware handles. It is for this reason that we **can't have a global location** that changes across different invocations. Each invocation of the same function uses the same global which also holds primitives like `URL` or `Request` so changing an hypothetical `globalThis.location` per request would affect concurrent requests being handled.

Then, it is not possible to use relative URLs in the same way the browser does because we don't have a global to rely on to use its host to compose a URL from a relative path.

### Why it works today

We are **not** validating what is provided to, for example, `NextResponse.rewrite()` nor `NextResponse.redirect()`. We simply create a `Response` instance that adds the corresponding header for the rewrite or the redirect. Then it is **the consumer** the one that composes the final destination based on the request. Theoretically you can pass any value and it would fail on redirect but won't validate the input.

Of course this is inconsistent because it doesn't make sense that `NextResponse.rewrite('/test')` works but `fetch(new NextRequest('/test'))` does not. Also we should validate what is provided. Finally, we want to be consistent with the way a browser behaves so `new Request('/test')` _should_ not work if there is no global location which we lack.

### What this PR does

We will have to deprecate the usage of relative URLs in the previously mentioned scenarios. In preparation for it, this PR adds a validation function in those places where it will break in the future, printing a warning with a link that points to a Next.js page with an explanation of the issue and ways to fix it.

Although middleware changes are not covered by semver, we will roll this for some time to make people aware that this change is coming. Then after a reasonable period of time we can remove the warning and make the code fail when using relative URLs in the previously exposed scenarios.
2022-01-19 15:10:25 +00:00
Mosaad
2518a5a4c7
docs: fix url (#33409) 2022-01-18 00:26:24 +01:00
Steven
7f6afa4a89
Update links in next export + next/image error message (#33317)
Minor changes to this error message to link to latest docs
2022-01-14 15:19:52 +00:00
Rich Haines
d291aa9134
Refactor data fetching API docs (#30615)
Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-01-12 08:56:51 +01:00
JJ Kasper
57a87050e7
Add util for normalizing errors (#33159)
* JSON.stringify generic errors

* Add util for normalizing errors

* lint-fix

* Add better error for null case as well

Co-authored-by: Michael Ozeryansky <mozeryansky@users.noreply.github.com>
2022-01-11 14:40:03 -06:00
JJ Kasper
efabf81e23
Add util for generating new tests/error documents (#33001)
* Add util for generating new tests/error documents

* update compiled

* lint-fix

* apply suggestions

* update wording

* update compiled
2022-01-06 09:45:04 -06:00
Houssein Djirdeh
d72f5bd69d
[ESLint] Adds lint rule to flag usage of <head> (#32897)
## Bug

- [X] Related issues linked using `fixes #number`
- [X] Tests added
- [X] Errors have helpful link attached, see `contributing.md`

Fixes #30142
2021-12-31 05:09:44 +00:00
Chai
b562b902cb
fix: typo (#32820) 2021-12-26 13:08:19 +01:00
Gustavo Levano
2c709bb587
Fixed syntax error in the example of React Hydration Error (#32773)
## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2021-12-23 19:25:11 +00:00
Hannes Bornö
802f4dcf5d
next-swc: styled-jsx error checking and reporting updated (invalid-styled-jsx-children.md) (#31940)
Co-authored-by: Hannes Lund <hannes.lund.2@consultant.volvo.com>
2021-12-20 16:17:37 +01:00
Artur Parkhisenko
37d1100825
Change using-preact example dependencies and docs (#30394)
* change use-preact dependencies

* change stackblitz url to use https protocol

* change deprecated thing from the webpack5 doc
2021-12-11 15:19:49 +01:00
Rich Haines
6274733fcb
Fix error page doc for no server import in page (#32164)
* Fix error page doc for no server import in page

* Feedback changes
2021-12-07 18:24:27 +01:00
Hannes Bornö
466687e88e
SWC: Add error checks and tests to next-dynamic (#31683)
fixes #31520

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-11-26 14:22:28 +00:00
Gerrit Alex
d38dd3d7e6
fix: support function components in _document in no-page-custom-font (#31560) 2021-11-26 14:27:13 +01:00
JJ Kasper
4b538e9879
Add error link when hydration error occurs (#31519)
This adds an error document/link for hydration errors to help users debug these easier. While looking at adding this also noticed a typo in the dev-overlay which is fixed. 

<details>

<summary>screenshot</summary>

<img width="1109" alt="Screen Shot 2021-11-16 at 15 56 29" src="https://user-images.githubusercontent.com/22380829/142078200-6c036ed9-ca7f-4d26-ae07-eb9bd89e991a.png">

</details>

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2021-11-23 13:10:56 +00:00
Thibaut SABOT
d1adf1d503
Add eslint rule to prevent importing next/server outside of _middleware (#30973)
* Add eslint rule to prevent importing next/server outside of _middleware

* add error to manifest.json

Co-authored-by: Javi Velasco <javier.velasco86@gmail.com>
2021-11-12 17:44:39 -06:00
Maia Teegarden
bc88831619
Add next-swc jest transform (#30993)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-11-08 17:35:04 +01:00
Steven
14841c9430
Fix incorrect _document.js error when disableStaticImages: true (#30768)
Fixes #30600
2021-11-02 20:25:12 +00:00
Erlend Åmdal
31f3d69332
Fix link to documentation from deprecated target config message (#30607)
The page links to itself, but was presumably meant to link to "Output File Tracing" under "Advanced Features".
2021-10-29 09:18:25 +00:00
JJ Kasper
59712b16c7
Add note about no-optional to swc error doc (#30566) 2021-10-28 14:04:20 -05:00
JJ Kasper
00c53d632c
Update SWC failed error with link to discussion (#30469)
Links the failed to load bindings error document to the new discussion here: https://github.com/vercel/next.js/discussions/30468

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2021-10-27 18:25:08 +00:00
Javi Velasco
c497b3a5ff
Improve deprecation errors for new middleware API (#30316)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Steven <steven@ceriously.com>
2021-10-26 17:03:39 +02:00
Kara
f6c58cb83a
Warn when mutating res if not streaming (#30284)
In #29010, we started throwing an error if the res was mutated after
getServerSideProps() returned. This was to support classic streaming,
where it would be possible to accidentally mutate the response headers
after they were already sent. However, this change also caught [a few
non-streaming cases](https://github.com/vercel/next.js/pull/29010#issuecomment-943482743) that we don't want to break.

As such, with this change, we only throw the error if res is mutated
after gSSP returns *and* you've opted into using classic streaming.
Otherwise, we will only add a warning to the console.
2021-10-25 20:18:03 -05:00
JJ Kasper
a25c1dd15a
Add warning for large amount of page data (#29956)
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-10-25 21:07:05 +02:00
JJ Kasper
1a10ab8c39
Update error for failing to load SWC bindings (#30269) 2021-10-25 12:23:44 -05:00
Tim Neutkens
bc3ab3ce94
Move swcMinify out of experimental (#29810) 2021-10-25 13:49:11 +02:00
JJ Kasper
649b41704b
Add deprecation note for target (#30200)
* Add deprecation note for target

* Apply suggestions from code review

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

* Mention Vercel leverages the traces

Co-authored-by: Steven <steven@ceriously.com>
2021-10-24 10:38:24 -05:00
Tim Neutkens
08a7f7f31a
Enable SWC by default when there is no custom Babel config (#29811)
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
Co-authored-by: padmaia <padmaia@users.noreply.github.com>
2021-10-23 10:21:44 +02:00
Steven
ca65fd8f87
Change AVIF to opt-in via configuration (#30180)
AVIF (shown in purple) is generally slower to encode than WebP (shown in yellow) so it is probably not a good default for on-demand Image Optimization.

Instead, we'll let users opt-in via `formats` configuration.

![performance](https://user-images.githubusercontent.com/229881/138511198-b987d307-17c2-47c2-816f-766a43d77efd.png)
2021-10-22 21:08:03 +00:00
JJ Kasper
67681fe097
Replace middleware flag with warning (#30160)
Follow-up to https://github.com/vercel/next.js/pull/30154 this replaces the experimental flag with a warning that is shown once on usage instead.
2021-10-22 06:40:57 +00:00
Steven
6f3e9470a6
Ensure error message prints next.config.mjs (#30152)
This PR ensures we print the correct error message for either `next.config.js` or `next.config.mjs`, whichever was detected.
2021-10-21 23:04:40 +00:00
Thibaut SABOT
3b34626fc8
docs: remove mention of experimental pageDataCollectionTimeout (#30107)
Removing the mention of `experimental.pageDataCollectionTimeout` in the docs as it doesn't exist anymore.

Related discussion: https://github.com/vercel/next.js/discussions/29992
2021-10-20 19:35:32 +00:00
JJ Kasper
f068319d4d
Enable shared worker pool by default (#30110) 2021-10-20 14:06:43 -05:00
paul-creates
4bbe2651af
Update documentation to fix github cache key (#29983)
`?` is any optional character, it isn't the same as the `?` in regex which will match the preceding character 0 or more times.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes
2021-10-18 22:19:22 +00:00
Steven
0daaae32dc
Update docs for Prerender Error message (#30044)
Update docs to mention `undefined` doesn't work, use `null` instead
2021-10-18 20:49:34 +00:00
Steven
cc1f3b8a38
Add support for AVIF to next/image (#29683)
Add support for AVIF to `next/image`

- Fixes #27882 
- Closes #27432 

## Feature

- [x] Implements an existing feature request
- [x] Related issues linked
- [x] Integration tests added
- [x] Documentation added
- [x] Update manifest output
- [x] Warn when `sharp` is outdated
- [x] Errors & Warnings have helpful link attached
- [ ] Remove `image-size` in favor of `squoosh`/`sharp` (optional, need to benchmark)
2021-10-11 23:17:47 +00:00
Tim Neutkens
aa8a885599
Remove webpack 4 support (#29660)
Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-10-06 17:40:01 +02:00
Thien Do
f0eb9283f0
Update invalid-getstaticpaths-value.md (#29397)
Add the `fallback: 'blocking'` option to "Invalid getStaticPaths Return Value" error
2021-09-26 07:13:13 -05:00
JJ Kasper
ead56eaab6
Fix invalid project dir casing breaking Next.js on Windows (#29205)
This fixes Next.js running into unexpected errors on Windows when invalid casing for a project directory is used. I was able to reproduce the issue on my local Windows machine and this resolved the issue there. 

<details>

<summary>screenshot of error while reproducing</summary>

<img width="838" alt="Screen Shot 2021-09-18 at 23 21 40" src="https://user-images.githubusercontent.com/22380829/133915825-ac4abdd2-fcf8-4309-9873-e6d88dfe485d.png">

</details>

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/27396
Fixes: https://github.com/vercel/next.js/issues/16535
Fixes: https://github.com/vercel/next.js/issues/17592
2021-09-22 21:29:27 +00:00
JJ Kasper
e66908412b
Ensure manifests check has correct exit code on fail (#29183) 2021-09-17 11:30:54 -05:00
Kara
41484f62cc
Throw error if res is accessed after gSSP returns (#29010)
* Throw error if res is accessed after gSSP returns

Currently it's possible to access the `ServerResponse` through `context.res`
in `getServerSideProps()`. If one was to store that response and mutate
its headers or status code after gSSP returns (e.g. during rendering), it
would currently happen to work because of when headers are sent. However,
this is an anti-pattern that relies an implementation detail of the framework
and shouldn't be allowed. This will be particularly important once Next.js
starts to support basic streaming (two-part flush: routing then data) because
then the headers will be sent as soon as gSSP returns, which explicitly breaks
this pattern.

With this commit, the framework now throws an error in development mode if
the ServerResponse is accessed after gSSP returns.

* fixup! Throw error if res is accessed after gSSP returns
2021-09-13 17:10:46 -05:00
Tim Neutkens
9572b30849
Deprecate webpack 4 support (#28840) 2021-09-13 09:18:04 +02:00
Konstantin Popov
93bac0f2b7
Fix minor typo in no-img-element.md (#29027)
Fix minor typo: 

image optimization -> Image Optimization
2021-09-12 00:39:43 +00:00
Ismail Ghallou
8921d9115b
chore(examples): switch to Script component on the google analytics example (#27674)
## Documentation / Examples

- [x] Make sure the linting passes

Fixes https://github.com/vercel/next.js/pull/27674
2021-09-08 21:03:23 +00:00
Perry Olsson
3b55a37c81
Webpack rule to block importing images into _document (#28475) 2021-09-06 13:41:18 +02:00
matamatanot
71771df6fa
Add error page path for next-script-for-ga (#28643)
## Documentation / Examples

- [x] Make sure the linting passes

**My console**

> src/pages/_document.tsx#L14
> Use the `next/script` component for loading third party scripts. See: https://nextjs.org/docs/messages/next-script-for-ga

https://nextjs.org/docs/messages/next-script-for-ga is 404 now.
2021-08-31 07:41:27 +00:00
JJ Kasper
ead10f1f81
Fix handling for 204 status code with a body (#28479)
This ensures we handle 204 and 304 status codes correctly in API routes.  

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/28464
2021-08-25 15:52:43 +00:00
Steven
cb6290adf3
Update docs for sharp usage to mention Vercel (#28476)
There was some confusion in [this tweet](https://twitter.com/mtliendo/status/1430269174459338759) so I revised the docs around `sharp` usage.
2021-08-24 22:51:28 +00:00
stefanprobst
da4203d032
Add eslint rule for id attribute on inline next/script (#27853)
This adds a new ESLint rule to `eslint-plugin-next` to check that `next/script` components with inline content have the required `id` attribute.

Also adjusted the code example for inline scripts in the `next/script` docs, which were actually missing an `id` attribute.
And also updated the `next/scripts` integration test to also have the required `id` attribute.

Unsure about the required heading levels in the errors .md document (other examples have h1 and h4??)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-08-19 20:08:04 +00:00
Brody McKee
0d3fb75cb6
Add docs for ESLint plugin settings and rule options (#28059)
This PR adds documentation for the new `rootDir` setting (#27918), and for `next/no-html-link-for-pages`.

## Documentation / Examples

- [x] Make sure the linting passes
2021-08-19 09:07:30 +00:00
Jiachi Liu
7ea7c23866
Document usage of suspense option of next/dynamic (#28210)
## Documentation / Examples

- [x] Make sure the linting passes
- [x] Errors have helpful link attached, see `contributing.md` (for #28165, #27611)
- [x] Update test case
2021-08-18 01:21:22 +00:00
Rahul Gaba
da4d65252f
ESLint Plugin: Prefer next script component when using the inline script for Google Analytics. (#25147)
* Add a lint rule for using next script component when using inline script for Google Analytics.

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Update errors/next-script-for-ga.md

Co-authored-by: JJ Kasper <jj@jjsweb.site>

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-08-16 13:55:07 -05:00
JJ Kasper
039735350c
Add proper error when failing to load next.config.js (#28099)
This adds a proper error when we fail to load a user's `next.config.js` as the default node error can be confusing on its own and makes it seem like something failed internally in Next.js. We can expand on the included error doc added and potentially also add better syntax errors by parsing with acorn when we fail to load this file in the future. 

<details>

<summary>screenshot</summary>

<img width="962" alt="Screen Shot 2021-08-13 at 21 46 09" src="https://user-images.githubusercontent.com/22380829/129432211-6d858062-eea0-4bb9-8725-5bde98bdc47b.png">

</details>
2021-08-14 13:52:18 +00:00
Jesse Jafa
a28e775e88
[ESLint] Disallow <Script /> inside _document.js & <Script /> inside the next/head component (#27257)
## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. [Feature Request](https://github.com/vercel/next.js/discussions/26365)
- [x] Eslint unit ests added
- [x] Errors have helpful link attached, see `contributing.md`

Let me know if this looks good or something needs to be changed. I still need to add the error links and improve the eslint error messages.

I don't know if the CI runs the ESLint tests, but current all pass locally
2021-08-13 23:16:15 +00:00
Tobias Koppers
8bbb1cd353
use a shared worker pool for collecting page data and static page generation (#27924)
this avoid loading all code twice and hopefully improving performance
2021-08-12 19:54:49 +00:00
JJ Kasper
f56a1505c2
Fix incorrect error manifest path (#27970) 2021-08-11 12:07:09 -05:00
JJ Kasper
e61ea6f27b
Add manifest check step and add missing items (#27934) 2021-08-11 11:17:57 +02:00
Tim Neutkens
331fed89f3
Add Import trace for requested module when it fails to resolve (#27840)
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-08-09 14:38:26 +02:00
JJ Kasper
5eaca0ffe5
Document i18n locale limit (#27542)
Add check for i18n locale count and ensure the limit is documented

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-27 20:09:36 +00:00
Luís Galete
57501fa745
Fix typo in placeholder-blur-data-url error docs (#27510)
2021-07-26 17:04:47 +00:00
brijendravarma
74b159c850
Updated the Error message describing the alternative and added styles… (#14652)
The error message indicates better alternatives and added styles.css sample snippet for good visibility.

![Global_error_msg](https://user-images.githubusercontent.com/38159218/85950309-ac3bc100-b979-11ea-9a8d-4a356cb8007c.JPG)
![CSS-Global](https://user-images.githubusercontent.com/38159218/85950319-b2ca3880-b979-11ea-829a-24335fcfc93d.JPG)
2021-07-25 04:53:33 +00:00
Steven
1d347ba5dc
Fix typo in error message (#27438)
Fixes typo mentioned in https://github.com/vercel/next.js/pull/27346#discussion_r675477904
2021-07-23 14:07:09 +00:00
Alex Castle
1b733423d6
Use Sharp if available for Image Optimization (#27346)
* Use sharp for image transformations when available

* Refactor resizeImage and add sharp warning

* only show sharp warning once per instance

* Modify sharp error message

* Add documentation for optional sharp dependency

* Update docs/basic-features/image-optimization.md

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

* Import types for sharp

* Update lockfile

* Add testing against sharp

* use fs-extra for node 12

* Rename test sharp path variable

* Apply suggestions from code review

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

* update squoosh specific test

* Apply suggestions from code review

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

* update tests

* Apply suggestions from code review

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

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-07-22 18:11:17 -05:00
Rodrigo Roim
a3b2205b42
[errors/no-cache] Prevent GitHub Actions cache from going stale (#27362)
Closes: https://github.com/vercel/next.js/issues/27129

This configuration is similar to what we've been using at Statsig, and it's the best general purpose config I could think of.

At Statsig we also invalidate our caches weekly, since sometimes we spend weeks without updating dependencies for some of our NextJS apps, and the artifact bloat means GitHub starts invalidating other caches in our repo. I could add that step to this diff as well, but I think that's a bit too specific (likely only a problem in monorepos with several caches). In any case, the previous example also has this problem.

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-22 03:12:39 +00:00
Josh Flayhart
ddef873b3b
Update next-image-unconfigured-host.md (#24953)
* Update next-image-unconfigured-host.md

the docs are misleading because I tried this and still got yelled at by compiler, and then added domains and it worked?

* Update next-image-unconfigured-host.md

* Update next-image-unconfigured-host.md

* Update next-image-unconfigured-host.md

* Update next-image-unconfigured-host.md

* Update next-image-unconfigured-host.md

* Update next-image-unconfigured-host.md

* remove unrelated section

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-07-19 19:40:52 -05:00
JJ Kasper
14dd7c2954
Add warning for large number of routes (#27214)
This adds a warning when more than 1024 routes are added since it can have performance impacts and includes a document that we can add suggestions to reduce the number of routes being added. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-16 14:59:54 +00:00
Tobias Koppers
f9795fdd26
improve static generation UX (#27171)
#### improve export spinner

update at least once a minute in non-tty
update progress regularly when using the spinner
decrease frequency of the spinner (windows console output is expensive)

#### restart static page generation and collecting page data worker pools when hanging

when for 1 minute no activity happens on the worker pool, restart it
log a warning for hanging jobs

#### add page generation duration to summary tree

![image](https://user-images.githubusercontent.com/1365881/125750454-8845f1b1-faf0-4598-b7a4-ea796b884691.png)

for `[+n more pages]` is will show `(avg 321 ms)` when the average is over the threshold.
It will allocate 8 lines for preview pages (instead of 4) when they contain slow pages

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-16 09:21:44 +00:00
Steven
8151a7e0dc
Add minimumCacheTTL config for Image Optimization (#27200)
- Closes #23328  
- Related to #19914 
- Related to #22319 


## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`
2021-07-15 19:55:12 +00:00
Houssein Djirdeh
c46b405ba7
adds no duplicate head rule (#27179) 2021-07-15 13:04:17 -05:00
Tobias Koppers
7a8da9741d
add support for esm externals (#27069)
add `experimental.esmExternals: boolean | 'loose'` config option

remove `output.environment` configuration in favor of `target`

|                          | `esmExternals: false` (default) | `esmExternals: 'loose'` | `esmExternals: true` |
| ------------------------ | ------------------------------- | ----------------------- | -------------------- |
| import cjs package       | `require()`                     | `require()`             | `require()`          |
| require cjs package      | `require()`                     | `require()`             | `require()`          |
| import mixed package     | `require()` ***                 | `import()`              | `import()`           |
| require mixed package    | `require()`                     | `require()`             | `require()`          |
| import pure esm package  | `import()`                      | `import()`              | `import()`           |
| require pure esm package | Error **                        | `import()` *            | Error **             |
| import pure cjs package  | `require()`                     | `require()`             | Resolving error      |
| require pure cjs package | `require()`                     | `require()`             | `require()`          |

cjs package: Offers only CJS implementation (may not even have an `exports` field)
mixed package: Offers CJS and ESM implementation via `exports` field
pure esm package: Only offers an ESM implementation (may not even have an `exports` field)
pure cjs package: CommonJs package that prevents importing via `exports` field when `import` is used.

`*` This case will behave a bit unexpected for now, since `require` will return a Promise. So that need to be awaited. This will be fixed once the whole next.js bundle is ESM. It didn't work at all before this PR.
`**` This is a new Error when trying to require an esm package.
`***` For mixed packages we prefer the CommonJS variant to avoid a breaking change.

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-10 16:49:02 +00:00
Steven
1a8ad14089
Rename next/image dangerously-unoptimized to custom and warn when applicable (#26998)
Since we are no longer accepting new built-in loaders, users may wish to use a different cloud provider.

So this PR renames `dangerously-unoptimized` to `custom` to handle this case as well as the intention of `next export`.

If the user doesn't add a `loader` prop, we throw an error.
If the user adds a `loader` prop but it doesn't return the width, we print a warning.

- Follow up to #26847 
- Fixes #21079 
- Fixes #19612 
- Related to #26850
2021-07-08 19:35:19 +00:00
Maia Teegarden
b8f3a6d2d9
5MB -> 4MB body size limit (#26887)
This decreases the body size limit that triggers a warning from 5MB -> 4MB, which provides a little more wiggle room. Certain things like using base64 on body, headers, path, etc can cause the response to be larger than initially calculated. 

Initial PR: https://github.com/vercel/next.js/pull/26831
2021-07-02 23:17:56 +00:00
Maia Teegarden
538095c936
Warn when response body is larger than 5mb (#26831)
This PR adds a warning when api responses exceed 5mb since this will end up failing once deployed. In a future version this scenario will throw an error.

## Bug

- [x] Integration tests added

## Documentation / Examples

- [x] Make sure the linting passes
2021-07-02 19:27:33 +00:00
hiro
bdd1d85813
Fix typo on "occured" to "occurred" (#26876)
- Fix typo on "occured" to "occurred"
2021-07-02 16:06:50 +00:00
Tim Neutkens
59c742ee7f
Add instructions on how to add nextjs.org/docs/messages urls (#26865)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-07-02 13:39:00 +02:00
Peter Mekhaeil
94d7450a6e
chore: Enable Alex documentation linting for error pages (#26526) 2021-06-23 23:33:58 -05:00
Duc Le
4f3674cc37
Correct the word "remove" (#26258) 2021-06-17 13:47:02 +02:00
Vadorequest
75016716dc
Doc "no-sync-scripts" remove experimental notice (#26225)
It's not experimental anymore.




## Documentation / Examples

- [ ] Make sure the linting passes
2021-06-17 08:19:26 +00:00
Ivan Kalinin
c851da25f4
Fixed no-img-element documentation snippet. (#26154)
Module "next/image" has no exported member 'Image'.
It must be `import Image from "next/image"`
2021-06-16 08:57:45 +02:00
JJ Kasper
225b784393
Ensure all errors are added in manifest (#26129)
* Ensure all errors are added in manifest

* Add script doc to manifest
2021-06-15 13:36:25 -05:00
Gerald Monaco
775c7be517
Update react-version.md (#26093)
Forgot to update this in a previous PR.
2021-06-14 20:24:36 +00:00
Tim Neutkens
de08b1fff1
Remove unsupported examples (#26075)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-14 20:27:06 +02:00
JJ Kasper
1628e6d16c
Update client-side default error (#25997)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-06-11 16:23:45 +02:00
Steven
d8b59f3e46
Add errors for invalid placeholder=blur usage (#25953)
There are strict conditions for using `placeholder=blur` documented in #25949 but this will give the user a better understanding during `next dev` and links to the error.

- Error when `placeholder=blur` and no `blurDataURL`
- The Error for small images with `placeholder=blur` has been changed to a warning
- Added support for blurring a webp image
- Added error page linking to relevant docs
2021-06-10 18:51:35 +00:00
John Jago
c6ba29da00
docs: use descriptive links instead of "click here" (#25897)
* docs: use descriptive links instead of "click here"

Linking text such as "here" or "click here" is not accessible (and
doesn't look that great either). The best example of why it's better to
use link text that provides context is that some screen readers allow
navigation by links alone. If all links say "click here", then how does
the user know which one to go to?

I tried to make the minimal change necessary to make the link text
descriptive but had to reword a few sentences that didn't read well.

* Apply suggestions from code review

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-09 13:23:16 -05:00
Tim Neutkens
e1502bc9a5
Enable webpack5 for all apps (#25639)
* Enable webpack 5 by default for all apps

Still provides a way to opt-out using `webpack5: false` in next.config.js. Also throws an error for `future.webpack5`.

* Update tests

* Update test to run on webpack 4 instead of webpack 5

* disable webpack5 for legacy tests

* Fix stats-config for webpack4

* update tests

* update size for webpack4 test

* move basic suite first

* update basic test

* Add logs

* remove outdated testFutureDependencies job

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-06-07 15:48:29 -05:00
Houssein Djirdeh
8ae12db1e3
ESLint Plugin: Fix Document and Head import rules (#25730) 2021-06-07 12:40:28 +02:00
Tim Neutkens
9890565983
Add helpful error for link with multiple children (#25657)
Makes sure a helpful error is shown for `<Link>` with multiple children



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
2021-05-31 19:41:57 +00:00
Houssein Djirdeh
7426ebcbc3
ESLint Plugin: Image rules (#23402)
Adds a new image rule to `eslint-plugin-next`:

```
Do not use `<img>`. Use Image from `next/image` instead
```
2021-05-17 13:06:48 +00:00
Janicklas Ralph
7b0fe0d73b
Fix no-sync-scripts doc (#25062)
## Bug

Fix no-sync-scripts doc
2021-05-13 10:08:07 +00:00
Alessandro Ursino
2f142b622f
fix typo in path (#24978) 2021-05-11 13:05:03 +02:00
Houssein Djirdeh
6d0150f02e
ESLint Plugin: Prevent bad imports of next/document and next/head (#24832)
Adds lint rules to the Next.js ESLint plugin to:

- Disallow importing `next/head` inside `pages/_document.js`
- Disallow importing `next/document` outside of `pages/_document.js`

Both rules will be surfaced as **errors** within the recommended config of the plugin.

Fixes #13712 #13958
2021-05-10 21:28:06 +00:00
Houssein Djirdeh
44072205d8
ESLint Plugin: Custom Font at page-level rule (#24789)
Adds a lint rule warning to the Next.js ESLint plugin if a custom Google Font is added at page-level instead of with a custom document (`.document.js`)

_Note: This will be generalized to include more font providers in the near future._
2021-05-10 19:08:14 +00:00
Houssein Djirdeh
569da9d286
ESLint Plugin: passHref is not assigned (#24670)
Adds a lint rule warning to the Next.js ESLint plugin if `passHref=true` is not assigned for `<Link>` wrapping a custom component.

Fixes #23713
2021-05-10 18:35:11 +00:00
Houssein Djirdeh
59d50ff76d
ESLint Plugin: Google Font rules (#24766) 2021-05-10 10:03:28 +02:00
Houssein Djirdeh
656c2ef649
ESLint Plugin: Disallow <title> in Head from next/document (#24868)
Adds lint rule warning to the Next.js ESLint plugin to disallow `<title>` in `Head` imported from `next/document`.
2021-05-07 08:49:37 +00:00
Anthony Oyathelemhi
467ec2115c
Add additional reason for the Prerender Error when running next export (#24828)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-05-06 14:51:53 +02:00
Houssein Djirdeh
e783b0a2e8
Adds ESLint with default rule-set (#23702)
This PR re-includes ESLint with some notable changes, namely a guided setup similar to how TypeScript is instantiated in a Next.js application.

To add ESLint to a project, developers will have to create an `.eslintrc` file in the root of their project or add an empty `eslintConfig` object to their `package.json` file.

```js
touch .eslintrc
```

Then running `next build` will show instructions to install the required packages needed:

<img width="862" alt="Screen Shot 2021-04-19 at 7 38 27 PM" src="https://user-images.githubusercontent.com/12476932/115316182-dfd51b00-a146-11eb-830c-90bad20ed151.png">

Once installed and `next build` is run again, `.eslintrc` will be automatically configured to include the default config:

```json
{
  "extends": "next"
}
```

In addition to this change:

- The feature is now under the experimental flag and requires opt-in. After testing and feedback, it will be switched to the top-level namespace and turned on by default.
- A new ESLint shareable configuration package is included that can be extended in any application with `{ extends: 'next' }`
  - This default config extends recommended rule sets from [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react), [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks), and [`eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next)
- All rules in [`eslint-plugin-next`](https://www.npmjs.com/package/@next/eslint-plugin-next) have been modified to include actionable links that show more information to help resolve each issue
2021-04-30 11:09:07 +00:00
tarunama
7fd5a24d94
feat: add type to previewData (#21574)
`previewData` was already [typed declare variable](https://github.com/vercel/next.js/compare/canary...tarunama:feature/remove-any1?expand=1#diff-bd7baf53ff559d84461af8b2fd62cade7e2d8eb203f489e24a27c5b83a79a9d3L1380).
So I have defined `PreviewData` type, and adapt for avoiding error by type safe.
2021-04-20 18:13:48 +00:00
Gergo Tolnai
997b37ace3
Docs: add info about fallback to prerender-error (#22828) 2021-04-20 08:15:02 +00:00
JJ Kasper
6e7245cddb
Add error for getStaticPaths on non-dynamic page (#24188)
Noticed in this issue the reproduction was using `getStaticPaths` on a non-dynamic page incorrectly although we don't currently show an error for this. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

x-ref: https://github.com/vercel/next.js/issues/22931
2021-04-18 09:31:40 +00:00
Tim Neutkens
92e14f8d60
Update webpack5.md 2021-03-29 15:22:05 +02:00
Tim Neutkens
7da0f9c4cf
Update manifest.json 2021-03-29 15:16:10 +02:00
Tim Neutkens
46fa9b6421
Temporarily remove the automatic opt-in for webpack5 (#23497) 2021-03-29 13:42:04 +02:00
Tim Neutkens
7ecf24489a
Update static-dir-deprecated.md 2021-03-23 14:45:36 +01:00
Tim Neutkens
e52a224c21
Add manifest of error pages (#23310)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [x] Make sure the linting passes
2021-03-23 12:53:17 +00:00
Lee Robinson
a63c64a02d
Update error message for next export and next/image. (#23061) 2021-03-15 13:01:12 -05:00
Chris Meagher
bdc20c2657
Add Azure Pipelines example to no-cache docs (#22708)
I added this in to my own pipeline to fix the no-cache error and thought it may be of use to others.
2021-03-03 09:47:19 +00:00
Azeez Lukman
00d453d74b
expanded on No Router Instance (#21248)
Added more detailed explanation of why there is no router instance, and other ways to fix the error
2021-01-26 10:27:53 +00:00