Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

conditional import of dependencies

ANSWERED

I have a logger.js file in the common directory which imports fs which is fine when imported in app/index.js but throws a build error (which currently is by design) when imported into the companion/index.js. 

The error happens because fs is not supported in the companion.

So now the question is can I do a conditional import or try/catch around it so it will import correctly in both the app and the companion or do I have to have 2 different logger.js files for companion and app?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

An intermediate option would be to pass fs as an argument to logger.js when it's used in app, but pass something else (settingsStorage? URL?) when it's used in companion. logger.js would obviously need to adapt its behaviour accordingly.

Since there may not be much similarity between the code paths, this may not be worth doing in common.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

An intermediate option would be to pass fs as an argument to logger.js when it's used in app, but pass something else (settingsStorage? URL?) when it's used in companion. logger.js would obviously need to adapt its behaviour accordingly.

Since there may not be much similarity between the code paths, this may not be worth doing in common.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks Peter,  I have been thinking about this and that might actually be an option. I will look into that. 

 

Mike

Best Answer