Skip to content

Conversation

lihsai0
Copy link

@lihsai0 lihsai0 commented Sep 5, 2025

What?

Add a note for using @next/bundle-analyzer.

Why?

While using @next/bundle-analyzer, I encountered an issue and figuring out the cause. I believe this should be mentioned in the documentation.

@ijjk ijjk added the Documentation Related to Next.js' official documentation. label Sep 5, 2025
@ijjk
Copy link
Member

ijjk commented Sep 5, 2025

Allow CI Workflow Run

  • approve CI run for commit: 607fd80

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@@ -53,6 +53,8 @@ ANALYZE=true pnpm build

The report will open three new tabs in your browser, which you can inspect. Periodically evaluating your application's bundles can help you maintain application performance over time.

> **Note:** `create-next-app` generate the `scripts` in `package.json` is `"build": "next build --turbopack"`. The `--turbopack` will cause the analyzer not working.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rephrase and move it up to

https://nextjs.org/docs/app/guides/package-bundling#analyzing-javascript-bundles

Analyzing JavaScript bundles

I guess, what we want to say is that @next/analyzer doesn't yet support Turbopack builds.

Copy link
Author

@lihsai0 lihsai0 Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! This description is indeed a bit mess. What about we place the note below the "Generating a report" code block? Just to prevent someone from struggling to recall the content they read at the beginning? What do you think?

`@next/analyzer` doesn't yet support Turbopack builds.
Please ensure your `build` script doesn't include the `--turbopack` option when analyzing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doesn't support Turbopack builds is enough.

When you build, if you are using Turbopack that's clearly printed

I wonder if the analyzer should also warn about this 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

▲ Next.js 15.5.2 (Turbopack)

Creating an optimized production build ...
⚠ Webpack is configured while Turbopack is not, which may cause problems.
⚠ See instructions if you need to configure Turbopack:
https://nextjs.org/docs/app/api-reference/next-config-js/turbopack

It says I need to configure Turbopack. So I think maybe something wrong about Turbopack config directly and get into pitfall for fixing Turbopack.

Copy link
Contributor

@icyJoseph icyJoseph Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @next/bundle-analyzer is a thin wrapper around webpack-bundle-analyzer:

As it modifies the Webpack key in the config, the Turbopack run prints a warning that there might be problems. Some people used Webpack to compile other files for example, and that wouldn't happen if using Turbopack.

See these two comments:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now. But to fresh user to use @next/bundle-analyzer by following the step from docs, they will not get expect behavior and get a warning from Turbopack (not from @next/bundle-analyzer). That not make sense I think.🫣

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah - I do think we need a short good to know, or just straight up say in the text that when using Turbopack the analyzer is not working.

Let's add the note, with a link to https://nextjs.org/docs/app/api-reference/turbopack#getting-started - where one would see the --turbopack option

@lihsai0 lihsai0 force-pushed the patch-3 branch 2 times, most recently from aeb0fdf to fa22cc3 Compare September 10, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants