React-native: Error: Unable to resolve module `./utils/batch`

Created on 25 Apr 2019  ·  16Comments  ·  Source: facebook/react-native

🐛 Bug Report

after erasing node_modules folder i cannot compile anymore

 error: bundling failed: Error: Unable to resolve module `./utils/batch` 
 from `...node_modules\react-redux\lib\index.js`: 
 The module `./utils/batch` could not be found from `...node_modules\react-redux\lib\index.js`.

Environment

"react": "^16.8.6",
"react-native": "^0.59.5",
"react-redux" : "6.0.1"

i tryed to
npm install
npm start --clear-cache
npm cache clean --force

Bug Locked 📦Bundler

Most helpful comment

@alainib I have found the solution.
Problem:
This happens when you install react-redux ^7.0.0 and then downgrade to ^6.0.0.
People do this as expo doesn't have dependencies for hook features in ^7.0.0
Now that you have downgraded, it won't find './utils/batch'. This batch file is only found in ^7.0.0 which means expo is caching libraries with the directory names you are in. Even if you delete the entire project directory and recreate it spelled the same, the cache still brings this error up.

Solution:
instead of expo start or npm start
use expo r -c
this removes the cache associated with the build in that directory.

All 16 comments

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] alongside an explanation in your Environment: section.

react-native info :

info
  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
      Memory: 10.32 GB / 15.79 GB
    Binaries:
      Node: 10.15.2 - D:\work\nodejs\node.EXE
      Yarn: 1.13.0 - C:\work\Yarn\bin\yarn.CMD
      npm: 6.9.0 - D:\work\nodejs\npm.CMD

same issue here
React Native Environment Info:
System:
OS: Linux 4.15 Ubuntu 16.04.5 LTS (Xenial Xerus)
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 1.46 GB / 15.53 GB
Shell: 4.3.48 - /bin/bash
Binaries:
Node: 11.10.0 - /usr/local/bin/node
npm: 6.7.0 - /usr/local/bin/npm
SDKs:
Android SDK:
API Levels: 24, 26, 27, 28
Build Tools: 26.0.2, 27.0.3, 28.0.3
System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.57.8 => 0.57.8
npmGlobalPackages:
react-native-cli: 2.0.1

@alainib this needs a reproduction. Can you provide a minimal example showing the issue? Otherwise it's not actionable on our side.

@alainib this needs a reproduction. Can you provide a minimal example showing the issue? Otherwise it's not actionable on our side.

thank you for help , what did you need ? can i send you the package.json file ?

I need a full project where I can run commands, etc to investigate. You can also send me a zip through email (it's pretty easy to find) if you cannot share it publicly.

This is a huge issue. I cannot use react-redux ^7.0.0 as expo doesn't support the new hook dependencies.
I cannot use ^6.0.0 as it always gives me the error

Unable to resolve module ./utils/batch 
 from ...node_modules\react-redux\lib\index.js: 

@alainib I have found the solution.
Problem:
This happens when you install react-redux ^7.0.0 and then downgrade to ^6.0.0.
People do this as expo doesn't have dependencies for hook features in ^7.0.0
Now that you have downgraded, it won't find './utils/batch'. This batch file is only found in ^7.0.0 which means expo is caching libraries with the directory names you are in. Even if you delete the entire project directory and recreate it spelled the same, the cache still brings this error up.

Solution:
instead of expo start or npm start
use expo r -c
this removes the cache associated with the build in that directory.

@alainib I have found the solution.
Problem:
This happens when you install react-redux ^7.0.0 and then downgrade to ^6.0.0.
People do this as expo doesn't have dependencies for hook features in ^7.0.0
Now that you have downgraded, it won't find './utils/batch'. This batch file is only found in ^7.0.0 which means expo is caching libraries with the directory names you are in. Even if you delete the entire project directory and recreate it spelled the same, the cache still brings this error up.

Solution:
instead of expo start or npm start
use expo r -c
this removes the cache associated with the build in that directory.

i never used or installed expo :(

@alainib expo uses Metro as a bundler, and this bundler has a cache that lives in a OS's tmp directory, so the effect may be similar.

Have you tried purging your node_modules directory, installing everything all over again and then running yarn react-native start --reset-cache? This command will start Metro server with cache being cleared.

it finally worked thank you

  • delete node_modules folder
  • package.json : "react": "16.8.3", "react-native": "0.59.2", "react-redux": "6.0.1"
  • npm install
  • live the node_modules\react-native\scripts\launchPackager.bat as it with node "%~dp0..\cli.js" start
  • change @react-native-community\cli\build\commands\runAndroid\runAndroid.js :

    const procConfig = { cwd: process.cwd() }

  • npm cache clean --force

  • npm start --clear-cache
  • react-native start --reset-cache
    AND THIS STEP I DIDNT DONE BEFORE
  • delete C:\Users\YOURUSERNAME\AppData\Local\Temp\metro-cache

I'm pretty sure this wouldn't happen (didn't happen to me at least) if you used Yarn instead of npm, it's just way more reliable :). Anyway, glad you sorted it out! I feel we're good to close it now then.

@alainib I have found the solution.
Problem:
This happens when you install react-redux ^7.0.0 and then downgrade to ^6.0.0.
People do this as expo doesn't have dependencies for hook features in ^7.0.0
Now that you have downgraded, it won't find './utils/batch'. This batch file is only found in ^7.0.0 which means expo is caching libraries with the directory names you are in. Even if you delete the entire project directory and recreate it spelled the same, the cache still brings this error up.

Solution:
instead of expo start or npm start
use expo r -c
this removes the cache associated with the build in that directory.

saved my life, thank you

@thymikee I can confirm using yarn instead solved the issue for me

@thymikee I can confirm using yarn instead solved the issue for me

yarn and that solution of alainib

它终于工作了谢谢你

  • 删除node_modules文件夹
  • package.json: "react": "16.8.3", "react-native": "0.59.2", "react-redux": "6.0.1"
  • npm安装
  • node_modules\react-native\scripts\launchPackager.bat和它一样生活node "%~dp0..\cli.js" start
  • 改变 @react-native-community\cli\build\commands\runAndroid\runAndroid.js
    const procConfig = { cwd: process.cwd() }
  • npm cache clean --force
  • npm start --clear-cache
  • react-native start --reset-cache
    以及我之前完成的这一步
  • 删除 C:\Users\YOURUSERNAME\AppData\Local\Temp\metro-cache

它终于工作了谢谢你

  • 删除node_modules文件夹
  • package.json: "react": "16.8.3", "react-native": "0.59.2", "react-redux": "6.0.1"
  • npm安装
  • node_modules\react-native\scripts\launchPackager.bat和它一样生活node "%~dp0..\cli.js" start
  • 改变 @react-native-community\cli\build\commands\runAndroid\runAndroid.js
    const procConfig = { cwd: process.cwd() }
  • npm cache clean --force
  • npm start --clear-cache
  • react-native start --reset-cache
    以及我之前完成的这一步
  • 删除 C:\Users\YOURUSERNAME\AppData\Local\Temp\metro-cache

This method is really useful. Thank you.

Was this page helpful?
0 / 5 - 0 ratings