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.

IE11 errors on main.js because of `const` in `for (const ...`

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Next deployments should work in IE11.

Current Behavior

My Next deployment does not work in IE11.

The error is

SCRIPT1053: Const must be initialized
File: main.s, Line: 1, Column 503674

I looked at that place in main.js, which has this snippet–

... for(const e of Object.keys(o)) ...

I looked online, and apparently IE11 doesn’t allow const or let in for loops, like for (const var ....

I removed all these for (const and for (let forms from my code and redeployed, but got the same result. I believe it’s because there are 9 modules in my node_modules that use the for (const ... form. I can’t replace these modules.

Is there some way to have next build the code and convert these for (const and for (let forms to for (var or for (... so I can support IE11?

I am using Typescript, but I don’t think that should make a difference.

Steps to Reproduce (for bugs)

Deploy any code with a for (const loop in it.

Your Environment

Tech Version
next 5.1.0
node 9.8.0
browser IE version 11.0.9600.18860

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
omeraplakcommented, Feb 2, 2019

@kedarguy @tashburn i add babel polyfill to my project and fixed all.

This my setup;

.babelrc

"presets": [
		[
			"next/babel",
			{
				"preset-env": {
					"targets": {
						"browsers": [
							"IE >= 11"
						]
					},
					"useBuiltIns": "entry"
				}
			}
		]
	]

pages/_document.js

import '@babel/polyfill'

next.config.js

webpack: (config, { dev, isServer }) => {
        const originalEntry = config.entry;
	config.entry = async () => {
	const entries = await originalEntry()
	if (entries['main.js'].indexOf("@babel/polyfill") === -1) {
		entries['main.js'].unshift("@babel/polyfill")
	}
	return entries
	}
});

npm i --save @babel/polyfill

2reactions
timneutkenscommented, May 13, 2018

Going to close based on @oliviertassinari’s comment.

It’d be tremendously helpful if you provide full steps to reproduce when creating issues, otherwise it takes more time than it should to check out particular issues. Thanks 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

IE11 JS Error const name => function - jquery - Stack Overflow
The (value)=>{} syntax is called 'arrow function'. It is a feature of ecmascript2015 (ES6) , a script language specification.
Read more >
Video.js 7 to 8 Migration
Attempting to use Video.js 8 in IE11 will cause errors to be thrown. ... getComponent('Component'); const MyComponent = videojs.extend(Component, ...
Read more >
Building a webpack plugin to validate your bundle files for IE11
First, I've created a webpack compiler using Node.js API of webpack. Second, I've used `memfs` as the outputFileSystem because I don't want to...
Read more >
Handling common JavaScript problems - MDN Web Docs
Now we'll look at common cross-browser JavaScript problems and how to fix them. This includes information on using browser dev tools to ...
Read more >
let, var, and const - Go Make Things
let and const work in all modern browsers, and IE11 and up. They cannot be polyfilled. To push support back further, you would...
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