next.js: Unable to fix logs `[BABEL] Note: The code generator has deoptimised the styling of`

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

All environments are impacted.

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

Not available.

To Reproduce

By default, Babel will show these types of logs:

[BABEL] Note: The code generator has deoptimised the styling of some.generated.file.ts as it exceeds the max of 500KB.

It’s very easy to fix them, by using the Babel Compact Option

Unfortunatelly the current Next.js config loader does not support the compact option so there is no way to get rid of this error.

The only avilable workaround is to use overrides in the Webpack Next.js config:

config.module.rules.forEach((rule) => {
    rule?.oneOf?.forEach((nestedRule) => {
      if (nestedRule?.use?.loader?.includes('babel')) {
        nestedRule.use.options.overrides = nestedRule.use.options.overrides ?? []
        // Prevents duplicate overrides in dev.
        if (
          !nestedRule.use.options.overrides.some(
            (override) => override.test === nestedRule.test && override.compact === true
          )
        ) {
          nestedRule.use.options.overrides.push({
            test: nestedRule.test,
            compact: true,
          })
        }
      }
    })
  })

Describe the Bug

This will happen in any project with files bigger than 500KB that uses Babel.

Expected Behavior

I would expect to be able to get rid of those logs by setting the compact Babel option. Currently this option is being ignored.

Which browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 14
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

also facing using experimental.reactCompiler: true

When will this be resolved?

I created a PR to fix this issue: https://github.com/vercel/next.js/pull/53812

🤦‍♂️

🤦‍♂️