Luxon: Module `util` does not exist in React Native

Created on 15 Aug 2018  路  10Comments  路  Source: moment/luxon

I'm trying to build my react-native app (RN: 0.56.0) and I'm getting the following error:

error: bundling failed: Error: Unable to resolve module util from ../node_modules/luxon/build/cjs-browser/luxon.js: Module util does not exist in the Haste module map or in these directories: /../../../node_modules

Do I have to explicitly add util as a package?

help wanted bug

Most helpful comment

I'd prefer to remove the the dependency then. It's not worth causing so much pain.

All 10 comments

Hmm, no. I'm not even sure what that means.

util is a core Node module right?

Not in react-native, it has to be installed additionally from https://www.npmjs.com/package/utils

@ivosabev that's utils with s. util is a core Node module iirc

my bad, looks like util exists https://www.npmjs.com/package/util

My bad, wrong link. I meant, the util polyfill - https://www.npmjs.com/package/util

Here is a discussion about util missing from React Native: https://github.com/facebook/react-native/issues/526

Hmm, yeah. Is there a way in react-native to check if the require will fail? The problem is that it can't be handled in the catch.

No there is no way. RN will bundle all packages and user code before running the application. The error actually comes at the bundling stage.

I think it is best to add a message that the util polyfill is needed if you want to use Luxon on React Native, just like you have for the Intl support or use an alternative to util.inspect? (https://moment.github.io/luxon/docs/manual/install.html)

I'd prefer to remove the the dependency then. It's not worth causing so much pain.

I removed inspect altogether in 55ac17e6c0ed936bb098d77f933a5afbe24c787b, will release it soon

Was this page helpful?
0 / 5 - 0 ratings