So I have a weird situation with a circular reference between two files. A vastly over-simplified version looks something like this:
// petrify.js
import StoneObject from './object';
export default function petrify(value) {
If Array.isArray(value) {
return new SomethingElse(value);
} else {
return new StoneObject(value);
}
}
// object.js
import petrify from './petrify';
export default function StoneObject(source) {
const that = this;
Object.keys(source).forEach(function assignKey(key) {
that[key] = petrify(source[key]);
});
}
When I was using require instead of import, I had to do some weird stuff where I did the require later in the file, but switching to import seemed to clean this up, at least when I was using browserify-rails. When I try to switch to sprockets-commoner, however, I see an error in my javascript console:
Uncaught TypeError: (0 , _petrify2.default) is not a function
It points to a line in the compiled javascript that looks like:
So I have a weird situation with a circular reference between two files. A vastly over-simplified version looks something like this:
When I was using
require
instead ofimport
, I had to do some weird stuff where I did the require later in the file, but switching toimport
seemed to clean this up, at least when I was usingbrowserify-rails
. When I try to switch tosprockets-commoner
, however, I see an error in my javascript console:It points to a line in the compiled javascript that looks like: