vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.39k stars 26.78k forks source link

Unable to fix logs `[BABEL] Note: The code generator has deoptimised the styling of` #53807

Open nbouvrette opened 1 year ago

nbouvrette commented 1 year ago

Verify 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

nbouvrette commented 1 year ago

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

BadmWe commented 9 months ago

I am experiencing the same warning as I am trying to integrate markdown https://github.com/uiwjs/react-md-editor/issues/608

bombillazo commented 7 months ago

Please lets merge this! It clutters our logs with inoffensive outputs!

r34son commented 3 months ago

also facing using experimental.reactCompiler: true