Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge 18 (Object.fromEntries) not supported even with correct polyfills #16715

Closed
FBosler opened this issue Aug 31, 2020 · 8 comments · Fixed by #36426
Closed

Edge 18 (Object.fromEntries) not supported even with correct polyfills #16715

FBosler opened this issue Aug 31, 2020 · 8 comments · Fixed by #36426
Labels
good first issue Easy to fix issues, good for newcomers Webpack Related to Webpack with Next.js.
Milestone

Comments

@FBosler
Copy link

FBosler commented Aug 31, 2020

Bug report

using the following .babel.rc leads to a build that should in theory support edge 18.

{
    "presets": [
        [
            "next/babel",
            {
                "preset-env": {
                    "targets": "> 0.25%"
                }
            }
        ]
    ],
    "plugins": [
        ["styled-components", { "ssr": true }],
        [
            "module-resolver",
            {
                "root": ["."],
                "alias": {
                    "@/Components": "components",
                   ...
                    "@/Functions": "components/Concepts/Functions"
                }
            }
        ]
    ]
}

This can be confirmed by running npx browserslist "> 0.25%". However, when testing live via browserstack (as its pretty hard to actually install edge 18), it seems like this is not the case, as the following bug pops up:

TypeError
Object doesn't support property or method 'fromEntries'

To Reproduce

Unfortunately, it's pretty hard for me to reliably reproduce the bug in a minimal example as I can't even run edge 18 locally. However, navigating to https://staging-viteach.com/concepts/rational%20numbers with edge 18 AND logging in - no validation required - will produce the bug.

Expected behavior

Would think that the config creates the correct polyfill.

Screenshots

image

System information

  • OS: Windows 10 (runtime)
  • Browser (if applies) edge 18 (runtime)
  • Version of Next.js: 9.4.4 (buildtime)
  • Version of Node.js: 13.13 (buildtime)
@timneutkens timneutkens added the good first issue Easy to fix issues, good for newcomers label Aug 31, 2020
@eezing
Copy link

eezing commented Sep 1, 2020

@FBosler stacktrace available?

@FBosler
Copy link
Author

FBosler commented Sep 2, 2020

@FBosler stacktrace available?

Sorry, browserstack won't let me copy stuff, seems like its sandboxed. Not sure if the screenshot helps though. Thanks for looking into this.

image

@FBosler
Copy link
Author

FBosler commented Sep 27, 2020

Any news on this? Or is there a way to monkey patch this? I am encountering a surprising large number of errors for this.

@samovertonjr
Copy link

@FBosler the fix might be to npm install object.fromentriesthis is a polyfill. I'll try and do a fix in next but idk how polyfills are handled yet. This link might help explain it more microsoft/TypeScript#32803

@FBosler
Copy link
Author

FBosler commented Oct 1, 2020

@samovertonjr makes sense! Thx, I'll have a look.

@eezing
Copy link

eezing commented Oct 2, 2020

@FBosler It could be caused by a non-transpiled NPM module. I'm using a few NPM modules that aren't transpiled, next-transpile-modules solved my problem.

@tkrotoff
Copy link

tkrotoff commented Feb 1, 2021

Check https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills

Create src/polyfills.js:

// https://github.com/vercel/next.js/pull/15772#discussion_r463984612
import 'core-js/features/object/from-entries';

and import it inside your custom src/pages/_app.js:

// https://nextjs.org/docs/basic-features/supported-browsers-features#custom-polyfills
import '../polyfills';

function App({ Component, pageProps }) {
  return (
    <Component {...pageProps} />
  );
}

export default App;

Why do we have to do this? Because Next.js does not include all polyfills. Instead @timneutkens decided to include only the most common ones (#15772 (comment), #11714) to avoid increasing the bundle size.

Be ready for hours of IE/old Edge debugging in a VM to understand what fails (can be hard considering how basic and slow IE dev tools are).

In a regular React app without Next.js, you would simply import 'core-js' and be done: no worries about a npm dependency update that might introduce the use of a basic JS feature not polyfilled by Next.js.

FYI Object.fromEntries() core-js polyfill is 5 lines of code.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants