question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object.keys non-object coercion not working in IE 11

See original GitHub issue

Bug report

Describe the bug

The argument passed to the Object.keys method should be coerced to an object from ES2015 onward. As illustrated in the example taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys.

// In ES5
Object.keys('foo');  // TypeError: "foo" is not an object 

// In ES2015+
Object.keys('foo');  // ["0", "1", "2"]     

However, this behaviour is not pollyfilled in Next.js for IE 11.

To Reproduce

  1. Download the reproduction available at https://github.com/tomdohnal/object-keys-ie-repro
  2. Use yarn dev or npm run dev to start the development server
  3. Open the page in IE 11 and it crashes.

Expected behavior

It should coerce the argument passed to Object.keys to object and not crash.

System information

  • OS: [Windows 10]
  • Browser [e.g. IE 11]
  • Version of Next.js: [e.g. 9.3.6]
  • Version of Node.js: [e.g. 12.14.0]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Timercommented, May 11, 2020

Ooh, Object.keys exists in IE9 it seems. I do not believe we override existing browser globals to introduce new behavior. Let’s take a deeper look into this though.

1reaction
tomdohnalcommented, May 11, 2020

Yeah it exists but lacks the coercion functionality which was added as a part of the ES6 spec…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.keys not working in internet Explorer - Stack Overflow
Object.keys is not avaiable in IE < 9. As a simple workaround you could use: if (!Object.keys) { Object.keys = function(obj) { var...
Read more >
Object.keys() - JavaScript - MDN Web Docs
Non -object arguments are coerced to objects. Only strings may have own enumerable properties, while all other primitives return an empty array.
Read more >
Object.keys() - The Vanilla JS Toolkit
Object.keys() polyfill */ // From ... 'object' || obj === null)) { throw new TypeError('Object.keys called on non-object'); } var result = [],...
Read more >
Object.preventExtensions() - JavaScript
The Object.preventExtensions() method prevents new properties from ever being added to an object (i.e. prevents future extensions to the object).
Read more >
Object orientation - The Apache Groovy programming language
The key differences between Groovy classes and their Java counterparts are: Classes or methods with no visibility modifier are automatically public (a special ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found