Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require cycle #183

Open
mengerzhuanyong opened this issue Sep 14, 2018 · 81 comments · Fixed by leyserkids/rn-fetch-blob#1 · May be fixed by #357
Open

Require cycle #183

mengerzhuanyong opened this issue Sep 14, 2018 · 81 comments · Fixed by leyserkids/rn-fetch-blob#1 · May be fixed by #357

Comments

@mengerzhuanyong
Copy link

Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/FileReader.js -> node_modules/rn-fetch-blob/index.js

It is recommended to solve this problem!

@reilem
Copy link

reilem commented Sep 17, 2018

I'm also getting these warnings on the new version of react-native.

Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Blob.js -> node_modules/rn-fetch-blob/index.js
Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/XMLHttpRequest.js -> node_modules/rn-fetch-blob/index.js
Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/FileReader.js -> node_modules/rn-fetch-blob/index.js
Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Fetch.js -> node_modules/rn-fetch-blob/index.js

@joegoodall2
Copy link

joegoodall2 commented Sep 25, 2018

Same issue

@zhaiyjgithub
Copy link

same issue

1 similar comment
@mitevdev
Copy link

mitevdev commented Oct 5, 2018

same issue

@tenwiz
Copy link

tenwiz commented Oct 14, 2018

Yes, I've faced the same issue here.

@tenwiz
Copy link

tenwiz commented Oct 14, 2018

Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Blob.js -> node_modules/rn-fetch-blob/index.js

@tskorupka
Copy link

Same issue :(

@burtek
Copy link

burtek commented Oct 24, 2018

same here

@rodrigowpl
Copy link

same here, any idea?

@sithartha
Copy link

I've got the same.

@tylerbarnett
Copy link

Same Here

@AsadSaleh
Copy link

Any one already working on this issue? Or any one has an idea to solve this?

@wd
Copy link

wd commented Nov 26, 2018

@AsadSaleh This is not a critical problem, just a warning for 'maybe there is something wrong in your code', so you can simply ignore this warning by add codes like bellow, and wait someone will fix this warning ...

YellowBox.ignoreWarnings([
    'Remote debugger is in a background tab which may cause apps to perform slowly',
    'Require cycle: node_modules/rn-fetch-blob/index.js',
    'Require cycle: node_modules/react-native/Libraries/Network/fetch.js'
]);

@qiaolin-pan
Copy link

any update on this ?

@soumyamishra89
Copy link

@wd This is a warning but needs to be dealt with. This has come up with new react-native version (0.57) and requires certain code restructuring in rn-fetch-blob library.

Is anyone working on this?

@AGOGD
Copy link

AGOGD commented Dec 13, 2018

I also encountered this problem today.

@zhuxianqin
Copy link

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

@nhuthuynh195
Copy link

nhuthuynh195 commented Jan 2, 2019

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

this problem has resolved, thanks brother

@Zbish
Copy link

Zbish commented Jan 16, 2019

there is going to be a PR for @zhuxianqin fix ???

@Faolain
Copy link

Faolain commented Jan 19, 2019

@zhuxianqin can you please submit a PR with this fix?

@zhuxianqin
Copy link

@zhuxianqin can you please submit a PR with this fix?

sorry, I don't know how to release github project, I will try to do it in several days

@zhuxianqin
Copy link

@zhuxianqin can you please submit a PR with this fix?

to develop this project, I need to follow instructions below:
https://github.com/joltup/rn-fetch-blob-dev
I have to test both on android & IOS
Sorry, I think it's better for the original owner to fix it

@msqar
Copy link

msqar commented Feb 10, 2019

@zhuxianqin seems that they are not adding it, it sucks man :(

Seems that you know this library a lot, though. Can you help me with something? I created this post
#305

@ThaJay
Copy link

ThaJay commented Feb 20, 2019

This should be fixed. I'm glad react-native now warns about this but there should have never been cyclic dependencies in the first place.

here it is solved with constructor injection:
https://stackoverflow.com/questions/38841469/how-to-fix-this-es6-module-circular-dependency/44226565#44226565

software-mansion/react-native-svg#773

Another way to solve this is to make an interface with a setter and a getter and require the interface instead of the original class. The original file uses the setter and all others use the getter.

interface.js:

let thing = {}

export function getThing () {
  return thing
}

export function setThing (thingToSet) {
  thing = thingToSet
}

thing.js:

import {setThing} from './interface'

class Thing {}

setThing(Thing)

other files:

import {getThing} from './interface'

const Thing = getThing()

@msqar
Copy link

msqar commented Feb 20, 2019

@ThaJay yea man, i receive like 6-7 warning notifications every time i refresh the app, is getting super annoying.
Do you have any idea how to apply this interface for this specific case?

@vitorverasm
Copy link

vitorverasm commented Feb 20, 2019

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

This did the trick on RN 0.57
This bug should be fixed...

@msqar
Copy link

msqar commented Feb 21, 2019

@vitor-veras i have to put the fetch-blob file in my app and edit it then? no other way until they fix this? :/ i don't get it, i assume i don't have to update these files directly from node_modules otherwise it will be over-written whenever i do another npm install... so how should i do it?

@vitorverasm
Copy link

vitorverasm commented Feb 21, 2019

That's only a warning from React Native, but it can slowdown the app performance. And yes if you update the package with npm/yarn the fix will go away. There's no proper aproach to this i think, hopefully the dev team fix this soon. There is actually a PR for this #296 .

@Faolain
Copy link

Faolain commented Mar 9, 2019

As mentioned by @alpha0010 in #296 one would encounter problems where RNFetchBlob is called within the files the import is removed from.

@ThaJay would you be able to submit a PR?

DarkLink363 added a commit to DarkLink363/rn-fetch-blob that referenced this issue Apr 12, 2021
Removed all the requiring cycles by changing all to use directly the NativeModules
@MSH786
Copy link

MSH786 commented Apr 14, 2021

import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

This also works in react-native-fetch-blob

Thanks Dude!

@ujangmisbah
Copy link

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

Thanks, this works fine

@storkyle
Copy link

storkyle commented Jun 23, 2021

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

Thanks brother, @zhuxianqin !

Note: I made a patch from @zhuxianqin's solution. I hope that makes it easier 😃

  1. install patch-package
  2. create a folder in your project called "patches"
  3. Inside "patches" folder get the patch from this gist (for convenience) https://gist.github.com/storkyle/d2f09ef376b3843915345150b0740977 . And name it as rn-fetch-blob+0.12.0.patch
  4. add "patch-package" in postinstall in package.json before doing yarn install.
    In package.json
"scripts": {
    "postinstall": "patch-package"
 } 
  1. run yarn install or npm install

@Remigius2011
Copy link

@storkyle , thanks for the patch. this works for me.

Question: does anybody know of a maintained fork or a good replacement for rn-fetch-blob?

@cristianoccazinsp
Copy link

https://github.com/RonRadtke/react-native-blob-util

@alpha0010
Copy link

Self promotion: I wrote https://github.com/alpha0010/react-native-file-access when this library was marked as unmaintained. API is similar, but implementation is completely new. Feature set reduced to what I thought were the essentials (less code/simpler code means fewer places for bugs... in theory).

@dexiouz
Copy link

dexiouz commented Jul 8, 2021

Modify these files can avoid require cycle:
IN DIR rn-fetch-blob/polyfill
all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js'
import {NativeModules} from 'react-native';
const RNFetchBlob = NativeModules.RNFetchBlob

Awesome. This fixed the issue for me

@keisan1231
Copy link

I resolved this script

Please write in ${root}/script/rn-fetch-blob_warning.js

var fs = require('fs');

const replaced = `import RNFetchBlob from '../index.js'`;
const replacement = `import {NativeModules} from 'react-native';\nconst RNFetchBlob = NativeModules.RNFetchBlob`;

const files = [
  'node_modules/rn-fetch-blob/polyfill/Fetch.js',
  'node_modules/rn-fetch-blob/polyfill/Blob.js',
  'node_modules/rn-fetch-blob/polyfill/XMLHttpRequest.js',
];

files.forEach(file => {
  fs.readFile(file, 'utf8', function (err, data) {
    if (err) {
      return console.log(err);
    }

    var result = data.replace(new RegExp(replaced, 'g'), replacement);
    fs.writeFile(file, result, 'utf8', function (err) {
      if (err) return console.log(err);
    });
  });
});

and in package.json

"scripts": {
.....
    "postinstall": "node scripts/rn-fetch-blob_warning.js"
  },

Please reinstall. (yarn install)
Then , waring vanishes

@gtaylor44
Copy link

Thank you @storkyle ... Don't need to manually patch each time packages are installed with this solution.

joblesspoet added a commit to joblesspoet/react-native-fetch-blob that referenced this issue Dec 25, 2021
vbejgrowicz added a commit to DogParkLabs/react-native-activestorage that referenced this issue Feb 11, 2022
rn-fetch-blob is no longer maintained and a [require cycle issue](joltup/rn-fetch-blob#183) constantly shows warnings in the latest version of RN when we start the app. This updates the package to use [react-native-blob-util](https://github.com/RonRadtke/react-native-blob-util) instead which is a maintained fork of the original package.
vbejgrowicz added a commit to DogParkLabs/react-native-activestorage that referenced this issue Feb 14, 2022
rn-fetch-blob is no longer maintained and a [require cycle issue](joltup/rn-fetch-blob#183) constantly shows warnings in the latest version of RN when we start the app. This updates the package to use [react-native-blob-util](https://github.com/RonRadtke/react-native-blob-util) instead which is a maintained fork of the original package.
@Faseeh-Abbas-Khan
Copy link

Modify these files can avoid require cycle: IN DIR rn-fetch-blob/polyfill all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js' import {NativeModules} from 'react-native'; const RNFetchBlob = NativeModules.RNFetchBlob

Worked for me

@satyabrata45
Copy link

Same issue

@rk-maker
Copy link

Modify these files can avoid require cycle: IN DIR rn-fetch-blob/polyfill all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js' import {NativeModules} from 'react-native'; const RNFetchBlob = NativeModules.RNFetchBlob

Thanks man this issue has been resolved

@biplovappservinc
Copy link

this is all are fixing not a permanent solution.

@technokasim
Copy link

Modify these files can avoid require cycle: IN DIR rn-fetch-blob/polyfill all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js' import {NativeModules} from 'react-native'; const RNFetchBlob = NativeModules.RNFetchBlob

It works for me. thanks

@pond
Copy link

pond commented Jun 19, 2022

Cyclic dependencies for almost 4 years and still not fixed?

That's... Unfortunate :-O

@tarouboy
Copy link

Try this forked package, still actively maintained.
https://github.com/RonRadtke/react-native-blob-util

@lfrallon
Copy link

lfrallon commented Oct 1, 2022

Hello, this still exists on:

"react": "18.0.0",
"react-native": "^0.69.0",
"rn-fetch-blob": "^0.12.0",

Update:

Fix after I installed "rn-fetch-blob": "0.13.0-beta.2" mentioned in #798 (comment).

@mickey35vn
Copy link

Modify these files can avoid require cycle: IN DIR rn-fetch-blob/polyfill all thease 4 files: Blob.js, Fetch.js, FileReader.js, XMLHttpRequest.js

// import RNFetchBlob from '../index.js' import {NativeModules} from 'react-native'; const RNFetchBlob = NativeModules.RNFetchBlob

it works for me, many thanks

cguino added a commit to BeApp/rn-fetch-blob that referenced this issue Jul 5, 2023
* master:
  Add timeout for ressource
  Fix issue : joltup#183 (comment)
  some fixes
  fix downloaded pdf

# Conflicts:
#	android/src/main/java/com/ReactNativeBlobUtil/Utils/PathResolver.java
#	polyfill/Blob.js
#	polyfill/Fetch.js
#	polyfill/XMLHttpRequest.js
@Adil7767
Copy link

Require cycle: node_modules/rn-fetch-blob/index.js -> node_modules/rn-fetch-blob/polyfill/index.js -> node_modules/rn-fetch-blob/polyfill/Fetch.js -> node_modules/rn-fetch-blob/index.js Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
same issue is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet