Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native : Unable to resolve module `tty` from ''.../node_modules/window-size/index.js": Module does not exist in the module map

Error

    loading dependency graph, done.
    error: bundling failed: Error: Unable to resolve module `tty` from `/MyWorks/rnTestTrials/myCurrencySample/node_modules/window-size/index.js`: Module does not exist in the 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 (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:158:1476)
        at ResolutionRequest.resolveDependency (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:92:16)
        at DependencyGraph.resolveDependency (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/node-haste/DependencyGraph.js:271:4465)
        at dependencies.map.relativePath (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/DeltaBundler/traverseDependencies.js:379:19)
        at Array.map (<anonymous>)
        at resolveDependencies (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/DeltaBundler/traverseDependencies.js:378:16)
        at /MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/DeltaBundler/traverseDependencies.js:203:33
        at Generator.next (<anonymous>)
        at step (/MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/DeltaBundler/traverseDependencies.js:296:307)
        at /MyWorks/rnTestTrials/myCurrencySample/node_modules/metro/src/DeltaBundler/traverseDependencies.js:296:467
     BUNDLE  [ios, dev] ./index.js ▓▓▓▓▓▓▓▓▓░░░░░░░ 60.2% (291/375), failed.

--

I tired the given solution in the error , and delete and re-initiate npm and also delete build from "./ios" and run again 'react-native run-ios'

this app working perfectily, but sudden shows this error and stop working,

enter image description here

tired all npm_module related solutions in the web,

versions

react-native-cli: 2.0.1
react-native: 0.54.0

package.json

{
  "name": "myCurrencySample",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "color": "2.0.0",
    "moment": "2.18.1",
    "react": "^16.3.0-alpha.1",
    "react-native": "^0.54.0",
    "react-native-extended-stylesheet": "^0.8.1"
  },
  "devDependencies": {
    "babel-jest": "22.4.1",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.2",
    "react-test-renderer": "^16.3.0-alpha.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

please help,

like image 966
Adarsh Avatar asked Mar 12 '18 09:03

Adarsh


1 Answers

I got the exact same error as yours, and i realized that while importing a different module, I accidentally imported this "import { width } from 'window-size';", this usually happens when IntelliSense is ON, for some IEDs like Visual Studio Code which imports a line of code that you did not intend to put. So to answer your question go through your files, probably the last file you were working on, and check if you accidentally imported "window-size" module which you did not intend to import and delete that line of code. And that's the short answer

If you have too many files to go through, then you can temporarily delete window-size folder inside node_modules in your project directory, WARNING DO NOT PERMANENT DELETE, KEEP IT SOMEWHERE SAFE, and make sure to close the metro bundler window, then run "react-native run-android or ios" again, the metro bundler should through an error but this time, the error will show exactly which file in your project has a problem, once you find it, delete that line of code, PUT BACK the window-size folder, Then clean your project by running "cd android && ./gradlew clean", close the metro bundler and run "react-native run-android or ios" again, it should work,

DISCLAIMER, This answer is only SPECIFIC to this question, because "Unable to resolve module" ERROR, can be caused by alot of things

like image 176
devbasil Avatar answered Nov 24 '22 06:11

devbasil