Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native sudden Unable to resolve module `fs` error

I got a sudden error that the module 'fs' is unable to resolve. But I have not used this module nor changed anything. My App suddenly returns this error while starting.

error: bundling failed: Error: Unable to resolve module fs from /Path/to/Project/node_modules/handlebars/lib/index.js: Module fs 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-*.

I already tried the four steps to resolve, several times but nothing helped. Any ideas what could be wrong?

like image 978
dav1904 Avatar asked Jun 14 '19 14:06

dav1904


2 Answers

For me, the issue was that VSCode had inserted some imports at the top of one of my js files. Very odd. These were the lines:

import { tsConstructorType } from '@babel/types';
import { logger } from 'handlebars';
like image 199
Dan Kronholm Avatar answered Oct 17 '22 22:10

Dan Kronholm


One of my node modules is depending on react-native-dotenv, but its code was using old import like import {} from 'react-native-dotenv'. But latest version of dotenv is using import {} from '@env'. Fixing this import in the module resolved the problem.

like image 24
Martin Atanasov Avatar answered Oct 17 '22 20:10

Martin Atanasov