Swr: Not compatible ie11

Created on 22 Feb 2020  Â·  9Comments  Â·  Source: vercel/swr

some code didnot transform to es5 ....

Most helpful comment

A fix is released in v0.2.3 :tada:

All 9 comments

We are having the same issue. The error reads:

Object doesn't support property or method 'repeat'

The app works in IE11, but when adding swr it crashes. Tried various polyfills without any luck.

Skjermbilde 2020-02-24 kl  10 20 16

String.prototype.repeat is part of ES6/ES2015; you would have to add an appropriate polyfill for browsers which don't support ES6.

I have tried to add that polypill multiple times, without any luck.

It's added at the top of the index.js and copied directly from the Mozilla code.
Skjermbilde 2020-02-25 kl  09 36 14

IE11 still gives the same error, and I have verified that the polyfill is being executed.

Skjermbilde 2020-02-25 kl  09 36 54

{
                test: /\.(js|tsx|ts)?$/,
                include: [path.join(process.cwd(), 'node_modules/swr')],
                loaders: [{
                    loader: 'babel-loader'
                }]
 }

i use babel to transform it. and it work in ie11.

Hi !
Did it works for you ?
I don't have same error. I'm using swr with Next.js.
Thanks for help

@beidan I've tried your webpack config, it fail also

image (2)

@joris-
Have a look at https://www.npmjs.com/package/next-transpile-modules if you are using Next.js. This helps transpile untranspiled modules in node_modules.

In your next.config.js

const withTM = require("next-transpile-modules")([
  "swr"
]);

module.exports = withTM();

@joris-
Have a look at https://www.npmjs.com/package/next-transpile-modules if you are using Next.js. This helps transpile untranspiled modules in node_modules.

In your next.config.js

const withTM = require("next-transpile-modules")([
  "swr"
]);

module.exports = withTM();

Thx I'll try

@beidan @joris-

This one works for me:

      {
        test: /\.(js|jsx)?$/,
        exclude: /node_modules\/(?!swr)/,
        use: {
          loader: 'babel-loader',
        },
      },

based on: https://github.com/babel/babel-loader/issues/171

A fix is released in v0.2.3 :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nainardev picture nainardev  Â·  4Comments

bcomnes picture bcomnes  Â·  3Comments

baoduy picture baoduy  Â·  4Comments

tiagocorreiaalmeida picture tiagocorreiaalmeida  Â·  3Comments

Svish picture Svish  Â·  4Comments