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

The browser build (produced by webpack) throws an error when loading #2081

Closed
paulovieira opened this issue Aug 28, 2019 · 1 comment
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@paulovieira
Copy link
Contributor

paulovieira commented Aug 28, 2019

Context

  • node version: none (this is relative to usage in the browser)
  • joi version: 16
  • environment (node, browser): browser
  • used with (hapi, standalone, ...): standalone

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

I want to simply load joi to use it in the browser (chrome). I created a client-side build using the webpack configuration provided in the "browser" directory.

When loading the build produced by webpack, an error in thrown:

Uncaught TypeError: Trace.setup is not a function
    at Object.internals.root (index.js:84)
    at eval (index.js:245)
    at Object.../lib/index.js (joi-browser.min.js:179)
    at __webpack_require__ (joi-browser.min.js:30)
    at joi-browser.min.js:94
    at joi-browser.min.js:97
    at webpackUniversalModuleDefinition (joi-browser.min.js:9)
    at joi-browser.min.js:10

This happens because webpack will always return plain js object here (lib/index.js):

const Trace = require('./trace');

Note: the "null-loader" is being used with lib/trace.js, but the effect is that it will erase all the code when creating the output. So we end up with a plain object when we require('./trace') (but still, a truthy value)

What did you expect ?

The browser build should load without any errors.

Fixed in pr #2082

hueniverse added a commit that referenced this issue Aug 28, 2019
Fix error thrown in the browser build. Closes #2081
@hueniverse hueniverse added the bug Bug or defect label Aug 28, 2019
@hueniverse hueniverse self-assigned this Aug 28, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Aug 28, 2019
@hueniverse
Copy link
Contributor

Thanks. I didn't know it was putting an empty object there.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants