Skip to content

DocumentIntelligenceClient is not a function #31

Open

Description

@Danscap

Edit 5/24/2024 5:50 PM
I have tried running the example from the legacy 3.1 documents and do not run into this issue. It seems this is only an issue with the v4.0 documentation.

Output is
`Pages:

  • Page 1 (unit: inch)
    8.5x11, angle: 0
    67 lines, 413 words
    Tables:
  • Extracted table: 3 columns, 5 rows (15 cells)
  • Extracted table: 2 columns, 2 rows (4 cells)`

Original
I have tried running the example from the v 4.0 documentation and received this error.
I am running Node 16.13.0 on Windows 10.

I'm not sure what I am doing wrong or if the example has faulty code. Any guidance or resolution would be helpful. Thank you.

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Copy and run the prebuilt model example from the javascript documentation

Any log messages given by the failure

An error occurred: TypeError: DocumentIntelligenceClient is not a function

Expected/desired behavior

Successfully analyze the sample document

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
Windows 10

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Activity

  1. HarshaNalluru commented on Jun 3, 2024

    @HarshaNalluru

    Here is an example that works.

    const DocumentIntelligence = require("@azure-rest/ai-document-intelligence").default,
        { getLongRunningPoller, isUnexpected } = require("@azure-rest/ai-document-intelligence");
    const { AzureKeyCredential } = require("@azure/core-auth");
    
    const { config } = require("dotenv")
    config()
    
    // sample document
    const invoiceUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
    
    // set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
    const key = process.env.KEY;
    const endpoint = process.env.ENDPOINT;
    
    async function main() {
    
        const client = DocumentIntelligence(endpoint, new AzureKeyCredential(key));
    
        const initialResponse = await client
            .path("/documentModels/{modelId}:analyze", "prebuilt-invoice")
            .post({
                contentType: "application/json",
                body: {
                    // The Document Intelligence service will access the URL to the invoice image and extract data from it
                    urlSource: invoiceUrl,
                },
            });
    
        if (isUnexpected(initialResponse)) {
            throw initialResponse.body.error;
        }
    
        const poller = await getLongRunningPoller(client, initialResponse);
    
        poller.onProgress((state) => console.log("Operation:", state.result, state.status));
        const analyzeResult = (await poller.pollUntilDone()).body.analyzeResult;
    
        const documents = analyzeResult?.documents;
    
        const result = documents && documents[0];
        if (result) {
            console.log(result.fields);
        } else {
            throw new Error("Expected at least one invoice in the result.");
        }
    
        console.log(
            "Extracted invoice:",
            result.docType,
            `(confidence: ${result.confidence || "<undefined>"})`,
        );
        console.log("Fields:", result.fields);
    }
    
    
    main().catch((error) => {
        console.error("An error occurred:", error);
        process.exit(1);
    });

    DocumentIntelligence is the default export of the SDK.
    createClient method can also be imported which returns an object of type DocumentIntelligenceClient.
    Moreover, you can name it however you want while importing a default export and it will work exactly the same.
    For instance,

    const DocumentIntelligenceClient = require("@azure-rest/ai-document-intelligence").default,
            { getLongRunningPoller, isUnexpected } = require("@azure-rest/ai-document-intelligence");
  2. JohnnyJamesNavarro commented on Feb 28, 2025

    @JohnnyJamesNavarro

    Harsha Nalluru (@HarshaNalluru) Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!

  3. ganxiyun commented on Mar 25, 2025

    @ganxiyun

    @HarshaNalluru Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!

    +1

  4. frank-nankivell commented on Jun 11, 2025

    @frank-nankivell

    @HarshaNalluru Hello! Thanks for your example. Using the imports the same way as you worked for me. Something weird that happens to me however is that calling poller.onProgress() or poller.pollUntilDone() fails. From my testing, getLongRunningPoller() appears to be returning the result of analyzing the document, not a poller to attempt polling the result. Have you seen that behavior before? Thanks!

    +1

  5. faikriza commented on Aug 17, 2025

    @faikriza

    Change the line:
    const poller = await getLongRunningPoller(client, initialResponse);
    to:
    const poller = getLongRunningPoller(client, initialResponse);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions