2

I have a component library that uses react as an external dependency it works alright from anywhere I tested.

I tried recently to import it from a spfx package and it keeps giving this error: enter image description here

What I don't get it is that the react import is available when the component is imported as well. What it looks like is either the way SPFX is loading React or how I am using it as an external dependency. the screenshot below you can see the react is imported with as a webpack module: enter image description here

I guess the question is how can I ensure my library uses the react from the SharePoint bundle or how can I make it work with SPFX without having to change my component library. Or the best way to handle those case is just to add the react dependency?

I am also curious how SharePoint exposes the React to the global since on module imports from SPFX it is not available in the window object. If anyone has documentation of how that happens would be great.

1 Answer 1

1

Ok... I figure out the error. on my externals I need to refer to react as in:

externals: {
  'react': 'react',
}

Also import react in every component that uses it. now it works and uses the current webpack bundle from sharepoint to import react.

import * as React from 'react';
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.