realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.74k stars 565 forks source link

util could not be found within the project or in these directories: node_modules #3915

Closed voonic closed 3 years ago

voonic commented 3 years ago

How frequently does the bug occur?

All the time

Description

Not able to run the project for both android and ios

Stacktrace & log output

Error: Unable to resolve module util from /Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/bson/dist/bson.browser.umd.js: util could not be found within the project or in these directories:
  node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  231 |
  232 |         
> 233 |       var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' ? Symbol['for']("nodejs.util.inspect.custom") : null;
      |                                                                                                                             ^
  234 |       exports.Buffer = Buffer;
  235 |       exports.SlowBuffer = SlowBuffer;
  236 |       exports.INSPECT_MAX_BYTES = 50;
    at ModuleResolver.resolveDependency (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:234:15)
    at DependencyGraph.resolveDependency (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/node-haste/DependencyGraph.js:413:43)
    at Object.resolve (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/lib/transformHelpers.js:317:42)
    at resolve (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/DeltaBundler/traverseDependencies.js:629:33)
    at /Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/DeltaBundler/traverseDependencies.js:645:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/DeltaBundler/traverseDependencies.js:644:33)
    at /Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/DeltaBundler/traverseDependencies.js:329:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/apple/Documents/Personal/Projects/wookie-movies-1-atsvpa/WookieMovies/node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:24)

Can you reproduce the bug?

Yes, always

Reproduction Steps

npm install realm

Version

10.6.1

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Ios, Android

Build environment

Which debugger for React Native: .. "dependencies": { "@react-native-community/netinfo": "^6.0.0", "@react-navigation/material-bottom-tabs": "^6.0.4", "@react-navigation/native": "^6.0.2", "@react-navigation/stack": "^6.0.6", "@types/react-native-vector-icons": "^6.4.8", "native-base": "^3.0.7", "react": "17.0.1", "react-native": "0.64.1", "react-native-fast-image": "^8.3.7", "react-native-flash-message": "^0.1.23", "react-native-gesture-handler": "^1.10.3", "react-native-linear-gradient": "^2.5.6", "react-native-paper": "^4.9.2", "react-native-safe-area-context": "^3.3.0", "react-native-screens": "^3.5.0", "react-native-star-rating": "^1.1.0", "react-native-svg": "^12.1.1", "react-native-vector-icons": "^8.1.0", "realm": "^10.6.1", "styled-components": "^5.3.0", "styled-system": "^5.1.5" }

moezbaccouche commented 3 years ago

I have the same issue. I even tried downgrading React-Native version to 0.63.2 and Realm to 10.2.0 but still no luck.

kneth commented 3 years ago

I am able to reproduce it. The problem is that BSON v4.5.0 doesn't work. Unfortunately, Realm JavaScript specifies BSON v4.4.0 or later.

As a workaround, you can remove node_modules/bson and reinstall BSON using npm install bson@4.4.0. If you are doing a fresh installation of Realm JavaScript, you can do npm install realm bson@4.4.0.

We will work together with the BSON team to get the issue solved: https://jira.mongodb.org/browse/NODE-3561

moezbaccouche commented 3 years ago

I am able to reproduce it. The problem is that BSON v4.5.0 doesn't work. Unfortunately, Realm JavaScript specifies BSON v4.4.0 or later.

As a workaround, you can remove node_modules/bson and reinstall BSON using npm install bson@4.4.0. If you are doing a fresh installation of Realm JavaScript, you can do npm install realm bson@4.4.0.

We will work together with the BSON team to get the issue solved: https://jira.mongodb.org/browse/NODE-3561

Thanks a lot @kneth that worked perfectly

kneth commented 3 years ago

BSON team has already a fix: https://github.com/mongodb/js-bson/pull/455.

lkoehl commented 3 years ago

BSON 4.4.0 doesn't work for me. Results in the same error as before.

JonatasSOliveira commented 3 years ago

BSON 4.4.0 doesn't work for me. Results in the same error as before.

same for me

Escandon1994 commented 3 years ago

Hi, this worked for me. The only I had to do was to install bson 4.4.0, go to bson.browser.umd.js in bson node_modules and copy all the content into node_modules/realm/node_modules/bson/dist/bson.browser.umd.js.

My node version: 14.17.5 npm version: 6.14.14 realm version: ^10.6.1

I don´t know if doing this is correct but it worked.

I hope my English is undertandable

HanifAnnurRahman commented 3 years ago

If you are using yarn, you can use selective version resolutions, add below code to your package.json to make realm use bson v4.4.0 :

"resolutions": {
  "realm/bson": "4.4.0"
},
voonic commented 3 years ago

I am able to reproduce it. The problem is that BSON v4.5.0 doesn't work. Unfortunately, Realm JavaScript specifies BSON v4.4.0 or later.

As a workaround, you can remove node_modules/bson and reinstall BSON using npm install bson@4.4.0. If you are doing a fresh installation of Realm JavaScript, you can do npm install realm bson@4.4.0.

We will work together with the BSON team to get the issue solved: https://jira.mongodb.org/browse/NODE-3561

This works, Thanks a ton.

kneth commented 3 years ago

@HanifAnnurRahman

If you are using yarn

Thank you for explaining how to do it when you are a yarn user.

kneth commented 3 years ago

BSON 4.5.1 has been released.