Joi: The plugin throws error when run on Edge Browser

Created on 6 Aug 2019  路  2Comments  路  Source: sideway/joi

Context

  • node version: 10.15.3
  • joi version: 14.3.1
  • environment : Microsoft Edge 44.17763.1.0
  • used with : React JS(create-react-app), joi-validation-strategy

The entire app crashes when opened in Edge and it throws the following error:

TypeError: Unable to get property 'includes' of undefined or null reference
in
/node_modules/joi/lib/types/object/index.js:436

The app runs fine on other browsers.

image

non issue

Most helpful comment

Seems Edge doesn't support pattern.flags:

/foo/g.flags //undefined

Instead of:

/foo/g.flags //"g"

Add a polyfill to support it:

if (RegExp.prototype.flags === undefined) {
  Object.defineProperty(RegExp.prototype, 'flags', {
    configurable: true,
    get: function() {
      return this.toString().match(/[gimsuy]*$/)[0];
    }
  });
}

refs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags

All 2 comments

Seems Edge doesn't support includes(). You will need to configure bable/webpack to add the needed shims.

Seems Edge doesn't support pattern.flags:

/foo/g.flags //undefined

Instead of:

/foo/g.flags //"g"

Add a polyfill to support it:

if (RegExp.prototype.flags === undefined) {
  Object.defineProperty(RegExp.prototype, 'flags', {
    configurable: true,
    get: function() {
      return this.toString().match(/[gimsuy]*$/)[0];
    }
  });
}

refs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags

Was this page helpful?
0 / 5 - 0 ratings