Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
49 lines
2.8 KiB
Plaintext
49 lines
2.8 KiB
Plaintext
---
|
|
title: Webpack 5 Adoption
|
|
---
|
|
|
|
## Why This Message Occurred
|
|
|
|
Next.js has adopted webpack 5 as the default for compilation. We've spent a lot of effort into ensuring the transition from webpack 4 to 5 will be as smooth as possible.
|
|
|
|
Your application currently has webpack 5 disabled using the `webpack5: false` flag which has been removed in Next.js 12:
|
|
|
|
```js filename="next.config.js"
|
|
module.exports = {
|
|
// Webpack 5 is enabled by default
|
|
// You can still use webpack 4 while upgrading to the latest version of Next.js by adding the "webpack5: false" flag
|
|
webpack5: false,
|
|
}
|
|
```
|
|
|
|
Using webpack 5 in your application has many benefits, notably:
|
|
|
|
- Improved Disk Caching: `next build` is significantly faster on subsequent builds
|
|
- Improved Fast Refresh: Fast Refresh work is prioritized
|
|
- Improved Long Term Caching of Assets: Deterministic code output that is less likely to change between builds
|
|
- Improved Tree Shaking
|
|
- Support for assets using `new URL("file.png", import.meta.url)`
|
|
- Support for web workers using `new Worker(new URL("worker.js", import.meta.url))`
|
|
- Support for `exports`/`imports` field in `package.json`
|
|
|
|
In the past releases we have gradually rolled out webpack 5 to Next.js applications:
|
|
|
|
- In Next.js 10.2 we automatically opted-in applications without custom webpack configuration in `next.config.js`
|
|
- In Next.js 10.2 we automatically opted-in applications that do not have a `next.config.js`
|
|
- In Next.js 11 webpack 5 was enabled by default for all applications. You could still opt-out and use webpack 4 to help with backwards compatibility using `webpack5: false` in `next.config.js`
|
|
- In Next.js 12 webpack 4 support was removed.
|
|
|
|
## Custom webpack configuration
|
|
|
|
In case you do have custom webpack configuration, either through custom plugins or your own modifications you'll have to take a few steps to ensure your applications works with webpack 5.
|
|
|
|
- When using `next-transpile-modules` make sure you use the latest version which includes [this patch](https://github.com/martpie/next-transpile-modules/pull/179)
|
|
- When using `@zeit/next-css` / `@zeit/next-sass` make sure you use the [built-in CSS/Sass support](/docs/app/getting-started/css) instead
|
|
- When using `@zeit/next-preact` use [this example](https://github.com/vercel/next.js/tree/canary/examples/using-preact) instead
|
|
- When using `@zeit/next-source-maps` use the [built-in production Source Map support](/docs/pages/api-reference/config/next-config-js/productionBrowserSourceMaps)
|
|
- When using webpack plugins make sure they're upgraded to the latest version, in most cases the latest version will include webpack 5 support. In some cases these upgraded webpack plugins will only support webpack 5.
|
|
|
|
## Useful Links
|
|
|
|
In case you're running into issues you can connect with the community in [this help discussion](https://github.com/vercel/next.js/discussions/23498).
|