joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 771 forks source link

Require cycle #768

Open SusulAdam opened 2 years ago

SusulAdam commented 2 years ago

"rn-fetch-blob": "0.12.0" "react-native": "0.63.3"

I am struggle with three warning Require cycle:

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 cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
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 cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
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.
tuantvk commented 2 years ago

@SusulAdam create file rn-fetch-blob.js from root project.

// rn-fetch-blob.js
const 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 (readErr, data) {
    if (readErr) {
      return null;
    }
    const result = data.replace(new RegExp(replaced, 'g'), replacement);
    fs.writeFile(file, result, 'utf8', function (err) {
      if (err) {
        return null;
      }
    });
  });
});

Run node rn-fetch-blob.js

dhon2407 commented 2 years ago

Is there a permanent solution to this? I don't have my node_modules included on the project repository.

JacquesWhite commented 2 years ago

@SusulAdam create file rn-fetch-blob.js from root project.

// rn-fetch-blob.js
const 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 (readErr, data) {
    if (readErr) {
      return null;
    }
    const result = data.replace(new RegExp(replaced, 'g'), replacement);
    fs.writeFile(file, result, 'utf8', function (err) {
      if (err) {
        return null;
      }
    });
  });
});

Run node rn-fetch-blob.js

Probably it is easier to use patch-package, But is there any reason to not include it this way in this repo?

GregoireDucharme commented 2 years ago

Same issue as https://github.com/joltup/rn-fetch-blob/issues/183 Something got merged 15 days ago https://github.com/joltup/rn-fetch-blob/pull/688.

Is there going to be a new release with those fixes ? :smile: