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

React native: unable to resolve module 'util' #3

Open
mfazekas opened this issue Mar 28, 2020 · 10 comments · May be fixed by #4
Open

React native: unable to resolve module 'util' #3

mfazekas opened this issue Mar 28, 2020 · 10 comments · May be fixed by #4

Comments

@mfazekas
Copy link

Error: undefined Unable to resolve module `util` from `node_modules/zealit/zealit.js`: util could not be found within the project.
@mfazekas
Copy link
Author

npm install util --save solves the issue in RN. Not sure if this package can anything to be more RN friendly

@mfazekas
Copy link
Author

Also in RN we'd want to add

        '$$typeof',
        'prototype',

the the ignored properties, console.log and HMR seems to be accessing those.

@mfazekas mfazekas linked a pull request Mar 28, 2020 that will close this issue
@zertyuio
Copy link
Member

Hi, thanks for this feedback.

About the util dependency, could you try this:
https://stackoverflow.com/questions/43055748/loading-modules-conditionally-in-react-native

In other words, update zealit/package.json in order to append:

"react-native": {
    "util": "~0.12.2"
}

Then npm i?
I don't have ReactNative on my computer, I can't do a quick test.

@mfazekas
Copy link
Author

I've added a PR #4 that implements and alternative solution it will not require('util') on react native.

I guess adding util as 'react-native' specific dependency works as well, but it's a bit pointless. As RN will not use util.inspect.custom for any inspection anyway.

I'll look into it if you prefer that to the conditional require in the .js

@zertyuio
Copy link
Member

zertyuio commented Mar 28, 2020

In fact, the PR will not work with nodejs, "navigator" is not defined in this context (at least v6.7.0). That's why I would like to explore the conditional depency.

If adding util is not good, could you try this ?

"react-native": {
    "util": false
}

If I understand stackoverflow response, util will look like an empty object.

@zertyuio
Copy link
Member

If:

"react-native": {
    "util": false
}

doesn't work, I will try something else.

@mfazekas
Copy link
Author

In fact, the PR will not work with nodejs, "navigator" is not defined in this context (at least v6.7.0). That's why I would like to explore the conditional depency.

Yes but my pr, has other not only conditional include of util it also adds rn specific inspect properties to ignore. We can definetedly do (typeof(navigator) === 'object' && navigator !== null) && navigator.product === 'ReactNative', that should work everywhere.

@zertyuio
Copy link
Member

Yes, I saw your PR, thanks for the proposal, I understand the issue. Before merging, i would like to explore the possibilities.

@mfazekas
Copy link
Author

@zertyuio sure i'll test the util: false later today or tomorrow

@mfazekas
Copy link
Author

mfazekas commented Mar 29, 2020

I've tested:

"react-native": {
    "util": "~0.12.2"
}

no util package was installed and same error on require

I've tested:

"react-native": {
    "util": false
}

no util package was installed and require('util') returned {}

So the second one seems to be an option too.

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

Successfully merging a pull request may close this issue.

2 participants