Nuxt.js: modern build includes core-js 3

Created on 9 Jan 2020  路  3Comments  路  Source: nuxt/nuxt.js

Version

v2.11.0

Reproduction link

https://hokify-data.s3.eu-central-1.amazonaws.com/empty-app-shared-components.zip

Steps to reproduce

  • use a nuxt template starter e.g.: npx create-nuxt-app test
  • edit nuxt.config.js and add under build:
    build: {
    babel: {
    presets({ envName }) {
    return [
    [
    '@nuxt/babel-preset-app',
    {
    corejs: { version: 3 }
    }
    ]
    ]
    }
    }
    comment: it's also happening with core-js2, but it seems with less modules included. e.g. there is no promise polyfill, which should not be there anyways but is with core-js3 (see what is actually happening).
  • run npm run analyze

What is expected ?

core-js should not be included, or at least only the minimum stuff that is somehow still needed in modern builds? are there any though?

What is actually happening?

corejs.png

Additional comments?

i'm not sure if this is maybe expected, but couldn't find any valid reason. according to esmodule babel documentation, promise is definitely supported in this case (https://www.ecma-international.org/ecma-262/6.0/#sec-promise-constructor) and therefore I see no reason why e.g. this one is included. I guess this is true also for the other includes.

In copmarison to the client build, there a are a lot less modules included already, but shouldn't it actually be gone at all?

bug-report

Most helpful comment

Hi @simllll , thanks for the issue reporting.

For modern build, modern browsers is decided by targets.esmodules of @babel/preset-env, but even for some modern browsers, es.promise in core-js is still needed as some of the modern browsers are not fully supporting promise specifications, like https://github.com/zloirock/core-js/issues/565#issuecomment-495987453 described.

NOTE(Dangerous): This may break some unfully supported functionalities in modern browsers, if you're 100% sure that you don't need the polyfills, you can use exclude to exclude them:

export default {
  modern: 'server',
  build: {
    babel: {
      presets({ envName }, [preset, options]) {
        options.corejs = { version: 3 }
        if (envName === 'modern') {
          options.exclude = ['es.promise']
        }
      }
    }
  }
}


More details if you're interested

That's the reason why promise is included, so the app may be lack of fully promise support in firefox 60-69 if you exclude the polyfill manually.

For other included core-js polyfills, you can use the same way to check if it should be included.

All 3 comments

Hi @simllll , thanks for the issue reporting.

For modern build, modern browsers is decided by targets.esmodules of @babel/preset-env, but even for some modern browsers, es.promise in core-js is still needed as some of the modern browsers are not fully supporting promise specifications, like https://github.com/zloirock/core-js/issues/565#issuecomment-495987453 described.

NOTE(Dangerous): This may break some unfully supported functionalities in modern browsers, if you're 100% sure that you don't need the polyfills, you can use exclude to exclude them:

export default {
  modern: 'server',
  build: {
    babel: {
      presets({ envName }, [preset, options]) {
        options.corejs = { version: 3 }
        if (envName === 'modern') {
          options.exclude = ['es.promise']
        }
      }
    }
  }
}


More details if you're interested

That's the reason why promise is included, so the app may be lack of fully promise support in firefox 60-69 if you exclude the polyfill manually.

For other included core-js polyfills, you can use the same way to check if it should be included.

Thank you for the great insights! Makes totally sense now, perfect summary of what's going on! Closing this now, should we link this issue from @nuxt/babel-preset-app as further explanation for polyfills and modern build?

just for reference, this could be something to look into to as well:
https://github.com/nuxt/nuxt.js/issues/6784

@babel/preset-modules for modern build

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danieloprado picture danieloprado  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

vadimsg picture vadimsg  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

maicong picture maicong  路  3Comments