import array of objects with a module as a property returns undefined when import twice

55
May 18, 2019, at 2:00 PM

I'm trying to import an array of objects that has a module as a property. The first file that imports the object has no problem, but the second one has undefined.

// file 1
export default [
  {
    property1: 'bar',
    property2: 'foo',
    property3: require('./somefile').default,
  },
  {
    property1: 'bar',
    property2: 'foo',
    property3: require('./file3').default,
  },
];

// file 2
import myArray from './file1';
console.log(myArray) // everything ok

// file 3
import myArrayAgain from './file1';
console.log(myArrayAgain); // undefined

here is an example: https://codesandbox.io/embed/boring-hodgkin-uk7q7

Answer 1

I have looked at your codesandbox example and I think you have a cyclic dependency. file1 depends on file2, but the console.log in file2 depends on file1 which would not have had been evaluated that point.

Now, in the example in the description, file1 depends on the result of file3and, therefore, the result of file3 cannot depend on the result of file1

So, consider making file1 require some other file as long as it's not file3

//file 1
export default [
  {
    property1: 'bar',
    property2: 'foo',
    property3: require('./somefile').default,
  },
  {
    property1: 'bar',
    property2: 'foo',
    property3: require('./file4').default,
  },
];
READ ALSO
I need to make this canvas transparent but none of the solutions are working

I need to make this canvas transparent but none of the solutions are working

i tried all the juery tricks and also the css tricks but none of them worki dont really know anything about canvas but trying to solve this for a day now

40
Return Object from map() function not Array

Return Object from map() function not Array

Sorry if the title is misleading I'm not sure how to accurately describe what I am looking for

25
Post comments on Facebook via console Chrome

Post comments on Facebook via console Chrome

I found this solution post comments on facebook page via console but doesn't work at now

41
Comparing two columns, same row, for first value that doesn't match

Comparing two columns, same row, for first value that doesn't match

I have two sheets, one is a mirror sheet, "Sheet2," that I use to store the values of the other sheet, "Sheet1" My goal is to have a function compare the two sheets for differences

45