microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
38 stars 31 forks source link

Support for browser only (Svelte + Vite)? #1381

Closed nine-2-five closed 2 months ago

nine-2-five commented 2 months ago

I have successfully tested a Kiota Typescript client in a standalone Node project ran with npx tsx index.ts. However my requirement is to call this client from a Svelte (Vite bundled) app, and that is browser only. Is there any chance this could happen, with current standings?

The plan was to use it from a Svelte SPA running inside MAUI HybridWebView.

baywet commented 2 months ago

Hi @nine-2-five Thank you for using kiota and for reaching out.

While we have no tested this specific framework, the dependencies and the generated code are supposed to work both in a node or browser context. Let us know if you have any additional comments or questions.

nine-2-five commented 2 months ago

I got it to compile, but this pops out in browser:

Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/@microsoft_kiota-abstractions.js?v=80e0625c' does not provide an export named 'UntypedNode' (at index.ts:5:135)
baywet commented 2 months ago

Thank you for the additional information.

Can you run npm list @microsoft/kiota-abstractions and share what results you get please?

nine-2-five commented 2 months ago

Sure, this the result: (I don't know whether you saw in my initial post, but, the client is working fine in the Node environment):

├── @microsoft/kiota-abstractions@1.0.0-preview.66 ├─┬ @microsoft/kiota-http-fetchlibrary@1.0.0-preview.65 │ └── @microsoft/kiota-abstractions@1.0.0-preview.66 deduped ├─┬ @microsoft/kiota-serialization-form@1.0.0-preview.54 │ └── @microsoft/kiota-abstractions@1.0.0-preview.66 deduped ├─┬ @microsoft/kiota-serialization-json@1.0.0-preview.66 │ └── @microsoft/kiota-abstractions@1.0.0-preview.66 deduped ├─┬ @microsoft/kiota-serialization-multipart@1.0.0-preview.44 │ └── @microsoft/kiota-abstractions@1.0.0-preview.66 deduped └─┬ @microsoft/kiota-serialization-text@1.0.0-preview.63 └── @microsoft/kiota-abstractions@1.0.0-preview.66 deduped

baywet commented 2 months ago

Thank you for the additional information. I wanted to confirm you were running on the latest version of the package.

Since UntypedNode is an interface, my guess is that it gets "erased at transpilation" but somehow something still refers to it. In the generated client, can you search for any reference to UntypedNode please and share how they are used here please?

nine-2-five commented 2 months ago

It is referenced on multiple lines in client/models/index.ts (I'm using Google Place object)

export interface GOpeningHours extends Parsable {
    /**
     * The open_now property
     */
    openNow?: boolean | null;
    /**
     * The periods property
     */
    periods?: Period[] | null;
    /**
     * The weekday_text property
     */
    weekdayText?: UntypedNode | null;
}
baywet commented 2 months ago

Thank you for the additional information.

Can you also share the import for the untyped node please?

nine-2-five commented 2 months ago

import { createUntypedNodeFromDiscriminatorValue, type AdditionalDataHolder, type Parsable, type ParseNode, type SerializationWriter, UntypedNode } from '@microsoft/kiota-abstractions';

baywet commented 2 months ago

Thank you for the additional information. That's the issue, the import for UntypedNode should have a type marker as well. Authored https://github.com/microsoft/kiota/pull/5477 to address the issue in the generator.

nine-2-five commented 2 months ago

Do you know when this will be available in NPM?

baywet commented 1 month ago

It's not a change of the NPM package but of the generator. Once the change is available with release 1.19 planned to go out on October the 4th, you'll need to refresh your client.

nine-2-five commented 1 month ago

Ah, sorry, I thought I installed it globally by npm, but it was installed by dotnet cmd.