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

Missing polyfill 'Includes' IE 11 #59

Open
fernandoagarcia opened this issue May 28, 2019 · 15 comments
Open

Missing polyfill 'Includes' IE 11 #59

fernandoagarcia opened this issue May 28, 2019 · 15 comments

Comments

@fernandoagarcia
Copy link

fernandoagarcia commented May 28, 2019

Using version 1.2.2 and I seem to get the following error on IE 11

object doesn't support property or method 'includes'

Vue-cli usually automatically includes missing polyfills except for this one. Is there a way to resolve the issue so I can get this to work on IE 11?

@davestewart
Copy link
Owner

Ah, sorry about that!

Most likely the String method; I'll look to polyfill that.

In the meantime, I guess add this to your project:

if (!String.prototype.includes) {
  String.prototype.includes = function (value) { return this.indexOf(value) > -1; }
}

Can you see if adding that works?

@fernandoagarcia
Copy link
Author

@davestewart yes that worked. Had to add it in the template HTML before all the bundled files. Thank you!

@davestewart
Copy link
Owner

Thanks for the ticket. I'll get that added in a future release :)

@bkarlson
Copy link

I cannot find, has it been incorporated yet? Many releases since then, and seems like an easy fix.

P.S. thanks a ton for this plugin, worked wonders with simplyfing vuex-related codebase!

@davestewart
Copy link
Owner

Hey @bkarlson - not added yet, but I'm going to go through all outstanding tickets next week and I'll add this then.

P.S. Glad you are enjoying it!

@JessicaSachs
Copy link

Just bit me :-)

Working around it w Babel’s core-js polyfills, which have to pollute the window to polyfill factory functions on String, Array, etc...

Hoping that one of our partners doesn’t do something weird with String.includes that we’ll mess up 🙏

When you implement the permanent fix, it’d be cool if you used a method that didn’t mutate String’s prototype. 🙇‍♀

@davestewart
Copy link
Owner

@JessicaSachs
Copy link

The actual code in the polyfill is fine. Globally mutating String is an issue for us. If it were a local function that vuex-pathify could use, that would be optimal.

@davestewart
Copy link
Owner

Globally mutating String is an issue for us

How come?

@JessicaSachs
Copy link

Because as a vendor/plugin, the websites we run on also mutate String. Sometimes their polyfills’ code relies on an incorrect implementation of String.includes

Widely popular pre-Babel library “MooTools” is particularly bad at writing incorrect implementations of polyfills. Lots of websites in developing worlds tend to use older tech and we can break their website if we stomp on window’s String/Array/etc

Babel has a lot of content on why global polyfills are bad... which is why they wrote a whole toolchain to enable local polyfilling via require/imports.

@JessicaSachs
Copy link

Think of Vue — no global polyfills needed. Runs anywhere without side affects. That’s ideal. I’m happy to put in a PR swapping out includes with the es5, local polyfill from MDN.

Thanks for hearing me out 🙇‍♀

@davestewart
Copy link
Owner

Fair point!

OK, I'll create an includes() helper or just let folks do it themselves.

@davestewart
Copy link
Owner

Looks like a straightforward rx replace:

([\w.]+)\.includes\((.+?)\)
includes($1, $2)

@JessicaSachs
Copy link

Closing the loop on this... I released the global polyfill and modifying String.includes started throwing errors on one of our major partner sites: Cannot redefine non-configurable property 'includes'

I had to take out vuex-pathify while you (or I, lemme know if you need me to make code changes) apply the fix you described above.

@chenweihuan
Copy link

I had the same problem and solved it ,add the following configuration If you're using Vue.

// vue.config.js
module.exports = {
  transpileDependencies: [
    'vuex-pathify'
  ]
}

If you use this scheme, you don't have to write polyfill yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants