02-16-2021 11:37
02-16-2021 11:37
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?
Answered! Go to the Best Answer.
02-16-2021 11:47
02-16-2021 11:47
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.
02-16-2021 11:47
02-16-2021 11:47
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.
02-16-2021 11:51
02-16-2021 11:51
Thanks Peter, I have been thinking about this and that might actually be an option. I will look into that.
Mike