I have a project in reactjs with a file structure more or less like this:
...
public/
src/
...
core/
ajax-interceptors.js
constants.js
global-ui.js
index.js
redux-store.js
service-mocker.js
...
.eslintrc.json
.gitignore
package.json
...
The file index.js
contains the following:
// @scripts
----------------------------------------------------------
// Aquí aparece el primer error
import { addAjaxInterceptors } from './ajax-interceptors';
// Dependency cycle detected.eslint(import/no-cycle)
----------------------------------------------------------
import { initializeGlobalUI } from './global-ui';
import { initializeReduxStore } from './redux-store';
import { initializeServiceMocker } from './service-mocker';
const initializeApp = () => {
const store = initializeReduxStore();
const serviceMocker = initializeServiceMocker();
const globalUI = initializeGlobalUI(store);
addAjaxInterceptors();
loadFonts();
const core = {
globalUI,
serviceMocker,
store
};
return core;
};
export const {
globalUI,
store
} = initializeApp();
The file ajax-interceptors.js
contains the following:
// @packages
import axios from 'axios';
// @scripts
// Aquí aparece el mismo error (Dependency cycle detected.eslint(import/no-cycle))
// Estoy llamando el objeto globalUI desde el index
// puesto que ya lo inicializé con el store de redux necesario para trabajar
import { globalUI } from '.';
const addResponseInterceptors = () => {
axios.interceptors.response.use(
(response) => {
if (Object.prototype.hasOwnProperty.call(response.data, 'data')) {
const {
data,
message,
messageType
} = response.data;
if (message && messageType) {
globalUI.showToastNotification({
msg: message,
type: messageType
});
}
return data;
}
return response.data;
},
(error) => Promise.reject(error)
);
};
export const addAjaxInterceptors = () =>
addResponseInterceptors();
How can I fix this circular dependencies error without affecting the architecture I have?