How to properly polyfill URLSearchParams in webpack?

Max Semikin picture Max Semikin · Aug 19, 2016 · Viewed 18.3k times · Source

I have a project that uses fetch polyfill from isomorphic-fetch. I would like to use URLSearchParams with it to submit POST data. For fetch to support URLSearchParams it first checks if it is available in global object. I though to use this polyfill for it but I don't know how to properly import it in webpack, so that fetch notices that it is available.

How can I accomplish this? Thank you!

Answer

peter46 picture peter46 · Dec 5, 2016

I had the same issue, had to switch to other polyfill to make it work, try this:

https://github.com/jerrybendy/url-search-params-polyfill

then simply add it to your webpack config:

entry: {
  bundle: [
    ...
    'url-search-params-polyfill',
    './src/entry'
  ]
}