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

Using with webpack #9

Closed
agriffis opened this issue Nov 2, 2018 · 1 comment
Closed

Using with webpack #9

agriffis opened this issue Nov 2, 2018 · 1 comment

Comments

@agriffis
Copy link
Contributor

agriffis commented Nov 2, 2018

I'd like to use this in a webpacked project, i.e. create-react-app

Trying to import it:

import TOML from '@iarna/toml'

results in this error:

Uncaught ReferenceError: require is not defined

It's coming from here:

image

Do you have a suggestion for using this with webpack?

@agriffis
Copy link
Contributor Author

agriffis commented Nov 2, 2018

In fact, everything seems to work if I just get rid of the eval:

const utilInspect = 'inspect'

So how about a try/catch?

let _inspect = 'inspect'
try {
  const utilInspect = eval(`require('util').inspect`)
  if (utilInspect && utilInspect.custom) {
    _inspect = utilInspect.custom
  }
}
catch (e) {
  /* eval require not available */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant