0

Is there any way that we can reference SPFx services outside of the webpart context? For example: using the AadHttpClient in a separate project that the webpart has as a dependency.

Currently we get a lot of errors if we do this. An example:

ERROR in ./node_modules/@microsoft/sp-http/lib/oauthTokenProvider/OAuthTokenProvider.js [0] Module not found: Error: Can't resolve '@ms/sp-client-shared' in 'C:\p\mp\MatchPoint.Intranet\Client\UI.Core\node_modules\@microsoft\sp-http\lib\oauthTokenProvider' [0] @ ./node_modules/@microsoft/sp-http/lib/oauthTokenProvider/OAuthTokenProvider.js 3:25-56 [0] @ ./node_modules/@microsoft/sp-http/lib/index.js

As far as I can tell, SPFx needs the webpart context in order to correctly solve dependency injection behind the scenes. Do you know if this is indeed the case, and if so, of any possible ways of setting that context somehow outside of the SPFx webpart?

  • What exactly to you mean by "a separate project that the webpart has as a dependency"? You can pass the context-object from the webpart to other parts of the same webpart (link), but i'm not sure if that's what you're looking for. – Helge S May 4 '18 at 12:59
  • for example, I want to use AadHttpClient in a separate file using import { AadHttpClient, HttpClientResponse } from "@microsoft/sp-http";. However, that does not work as expected because some dependencies cannot be resolved (I suppose the context is needed for that). I know I can pass the context, but can I somehow use that context for SPFx to correctly solve its dependencies under the hood? I don't know if this is any clearer – Serban May 4 '18 at 13:04
  • 1
    I understand, unfortunately i'm not sure if that's a designed-for scenario, you might be better off asking the SPFX-team on Github about this. – Helge S May 4 '18 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.