Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unable to resolve module `buffer` React Native

I am getting an error when I build my project on Android

error: bundling failed: Error: Unable to resolve module buffer from E:\SUNNYCLOCK-MOBILE\node_modules\safe-buffer\index.js: Module buffer does not exist in the Haste module map

This might be related to https://github.com/facebook/react-native/issues/4968 To resolve try the following: 1. Clear watchman watches: watchman watch-del-all. 2. Delete the node_modules folder: rm -rf node_modules && npm install. 3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-* or npm start -- --reset-cache. 4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*. at ModuleResolver.resolveDependency (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:161:1460) at ResolutionRequest.resolveDependency (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:91:16) at DependencyGraph.resolveDependency (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\node-haste\DependencyGraph.js:272:4579) at dependencies.map.relativePath (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\DeltaBundler\traverseDependencies.js:376:19) at Array.map () at resolveDependencies (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\DeltaBundler\traverseDependencies.js:374:16) at E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\DeltaBundler\traverseDependencies.js:212:33 at Generator.next () at step (E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\DeltaBundler\traverseDependencies.js:297:313) at E:\SUNNYCLOCK-MOBILE\node_modules\metro\src\DeltaBundler\traverseDependencies.js:297:473 BUNDLE [android, dev] ./index.js ▓▓▓▓▓▓▓▓░░░░░░░░ 51.9% (813/1143), failed.

my React native info is

Environment:
  OS: Windows 10
  Node: 8.9.1
  Yarn: 1.7.0
  npm: 4.6.1
  Watchman: Not Found
  Xcode: N/A
  Android Studio: Not Found

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: 0.55.4 => 0.55.4

How can I solve this issue

like image 726
Vinayak B Avatar asked Mar 18 '19 17:03

Vinayak B


1 Answers

First Install the missing dependency buffer :

npm install buffer --save OR yarn add buffer

Second

Up in the top of your file using buffer:

import { Buffer } from 'buffer';
global.Buffer = Buffer;

If you don't need to access Buffer directly, just paste the above code in your App.js file

like image 98
Hend El-Sahli Avatar answered Oct 15 '22 04:10

Hend El-Sahli