Yup vs Joi for frontend validation

In the past, it was true that joi lacked browser support, at least out of the box. It uses a few Node.js APIs, which aren’t available in the browser, to implement some of its features. It was still possible to use Browserify on it, or use the unofficial joi-browser npm package, but the process was cumbersome enough that it was less common to see joi used on the frontend. Yup was basically a workaround for that.

However, that information is out of date, as joi now includes an official browser build that’s easy to use and roughly the same size as yup. See its package.json: https://github.com/sideway/joi/blob/83092836583a7f4ce16cbf116b8776737e80d16f/package.json#L8

Your bundler, assuming it is set up correctly, should detect the browser build and use it automatically. For example, if you’re using Rollup, make sure you are using @rollup/plugin-node-resolve with the browser: true option.

I would strongly recommend using joi on the frontend now as you can share schemas between frontend and backend, which is really fantastic.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)