Skip to content
Advertisement

ES6 modules – imported constants undefined if not in React component

The only similar question I have found is this one but I can’t see how would I have caused a circular dependancy in this case:

I have a file exporting constants like so:

(choices array version is for using in Select inputs and the other one secures from typing errors in condition checks)

payments.constants.js

JavaScript

When they are imported inside any of my react components all works as expected.

MyReactComponent.js

JavaScript

But when I try to import the constants in another js file and merge them in another constants I got an error saying they are undefined:

defaultValues.js

JavaScript

ERROR message: TypeError: Cannot read property 'Cash' of undefined

enter image description here

Advertisement

Answer

Ok, in the end it was really a circular dependancy but a really complicated one because of a long chain of files imports. Something like:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement