Hi I m having some issu…

less than 1 minute read

Hi, I’m having some issue getting legacy code work correctly in my NX repository. • I have Lib-1 and Lib-2. • Lib-1 requires Lib-2. • Lib-2 is defined like this: export const Lib2 = function(){}Lib-1 calls it like this: const lib2 = require('@mystuff/Lib-2'); lib2 is now an object that holds Lib2 : { Lib2: function(){} } Is there a way to make this work? A lot of code is like that and it would be a bummer to have to change all of the calls of lib2 to import.

Responses:

Does it work when you import it like this?

const { lib2 } = require('@mystuff/Lib-2');

Yea - that’s what I did eventually :slightly_smiling_face: It’s the same as this const lib2 = require('@mystuff/Lib-2').lib2;

Right :slightly_smiling_face:

I think it’s better to just tell all devs to convert to import wherever they see it anyway :slightly_smiling_face:

Thanks!

Totally

And preferable named exports, and no default exports

Btw, WebStorm has this ‘intent’ that changes it for you - might exist in other editors too. Ideal when refactoring in legacy code

Updated: