"Namespace "{mypath}/node_modules/@microsoft/microsoft-graph-types/microsoft-graph"' has no exported member 'OneDriveLargeFileUploadTask' .ts(2694)"

Gal, Ofer 81 Reputation points
2021-04-07T20:50:49.203+00:00

Following https://learn.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=typescript, Typescript complains that it can't fine "OneDriveLargeFileUploadTask"
I have imports

import {Client} from "@microsoft/microsoft-graph-client"
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types"

How do I get the code to work?

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,569 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-04-08T07:58:53.59+00:00

    Hi @Gal, Ofer ,

    You're right. import {Client, OneDriveLargeFileUploadTask} from "@microsoft/microsoft-graph-client" works.

    Did you mean initialize client in @microsoft/microsoft-graph-client?

    import { Client } from "@microsoft/microsoft-graph-client";  
      
    const options = {  
    	authProvider, // An instance created from previous step  
    };  
    const client = Client.initWithMiddleware(options);  
    

    You could refer to the below articles for more:
    https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/HEAD/docs/CreatingClientInstance.md
    https://www.npmjs.com/package/@microsoft/microsoft-graph-client


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. MichaelHan-MSFT 18,016 Reputation points
    2021-04-09T02:48:13.497+00:00

    Hi @Gal, Ofer ,

    Usually, we instantiate MSGraphClient object from SharePoint context like this:

     import { MSGraphClient } from '@microsoft/sp-http';  
      
     const msGraphClient=this.context.msGraphClientFactory.getClient();  
    

    However, you are using const uploadTask: OneDriveLargeFileUploadTask = await OneDriveLargeFileUploadTask.create(client, file, options);. The Client instance in the code is different from msGraphClient instance .

    You have to instantiate a Client object as I mentioned above, below is my sample code:

    First, npm install msal

    Then:

    import { UserAgentApplication } from "msal";  
      
    import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider";  
    import { MSALAuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions';  
    import {Client, OneDriveLargeFileUploadTask} from "@microsoft/microsoft-graph-client";  
      
    const msalConfig = {  
            auth: {  
              clientId: "your_client_id", // Client Id of the registered application  
              redirectUri: "your_redirect_uri",  
            },  
          };  
          const graphScopes = ["user.read", "mail.send"]; // An array of graph scopes  
            
          // Important Note: This library implements loginPopup and acquireTokenPopup flow, remember this while initializing the msal  
          // Initialize the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js#1-instantiate-the-useragentapplication  
          const msalApplication = new UserAgentApplication(msalConfig);  
          const options = new MSALAuthenticationProviderOptions(graphScopes);  
          const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, options);  
          const client = Client.initWithMiddleware({  
            debugLogging: true,  
            authProvider: authProvider,  
          });  
    
    0 comments No comments