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

joi not usable in a browser environment #3019

Closed
sagevoice opened this issue Feb 17, 2024 · 1 comment
Closed

joi not usable in a browser environment #3019

sagevoice opened this issue Feb 17, 2024 · 1 comment
Assignees
Labels
bug Bug or defect

Comments

@sagevoice
Copy link

Runtime

browser

Runtime version

Chrome 121.0.6167.184 (Official Build) (x86_64)

Module version

17.12.1

Last module version without issue

joi-browser 13.4.0

Used with

react

Any other relevant information

See issue 2299 from Feb 12, 2020. Seems to be a longstanding problem not addressed in the past four years. Opening a new bug to get some fresh eyes on it. If there is some way to make this work I would love to know it. I tried all of the suggestions mentioned in 2299, and none of them worked for me.

With the require solution:

const Joi = require('joi');

The error is TypeError: Joi.validate is not a function

With the import the module without giving a name solution:

/*global Joi*/
import 'joi/dist/joi-browser.min.js'

The error is Uncaught ReferenceError: Joi is not defined. Same result if I try using lowercase joi as suggested in 2299.

As far as the discussion in 2299 about this being a breaking change, it seems to me that this has never worked in joi 17 - that it is just broken. However this was implemented in joi-browser 13.4.0 from Jun 14th 2018 still works today. Why can't Joi 17 at least be no worse that what was done back in 2018? I really want to get onto the current version, but not having it in the browser is a blocker for me.

What are you trying to achieve or the steps to reproduce?

I am trying to upgrade to use the use the latest joi in a web browser environment. See https://github.com/sagevoice/joi-bug for a simple create-react-app web app that tries to define a trivial schema and validate some data with it.
To reproduce:

git clone https://github.com/sagevoice/joi-bug.git
cd joi-bug
npm i
npm run start

Then check the developer console in the browser for errors.

What was the result you got?

TypeError: joi_dist_joi_browser_min_js__WEBPACK_IMPORTED_MODULE_2___default(...).validate is not a function

What result did you expect?

To have no errors and to see a console log with the message 'result null'.

@sagevoice sagevoice added the bug Bug or defect label Feb 17, 2024
@Marsup Marsup self-assigned this Feb 21, 2024
@Marsup
Copy link
Collaborator

Marsup commented Feb 21, 2024

Hi, thanks for the reproduction, that was helpful. Your demo works, you're just using a method that has been removed in v16 (4 years ago), Joi.validate hasn't been around for quite a while, I'm not sure which tutorial you followed but it's not very up-to-date 🙂

The only diff I had to apply was this:
image

@Marsup Marsup closed this as completed Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants