Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible regression in 1.16 Typescript client generation #4950

Closed
IkeOTL opened this issue Jul 9, 2024 · 11 comments
Closed

Possible regression in 1.16 Typescript client generation #4950

IkeOTL opened this issue Jul 9, 2024 · 11 comments
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question TypeScript Pull requests that update Javascript code

Comments

@IkeOTL
Copy link

IkeOTL commented Jul 9, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

TypeScript

Describe the bug

in 1.16 of the dotnet tool the clients are generating like this:

import { AnalyticsRequestBuilderNavigationMetadata, type AnalyticsRequestBuilder } from './analytics/index.js';
// @ts-ignore
import { HealthRequestBuilderRequestsMetadata, type HealthRequestBuilder } from './health/index.js';

in 1.15 they were generated like this:

import { AnalyticsRequestBuilderNavigationMetadata, type AnalyticsRequestBuilder } from './analytics/';
// @ts-ignore
import { HealthRequestBuilderRequestsMetadata, type HealthRequestBuilder } from './health/';

Expected behavior

should generate like this:

import { AnalyticsRequestBuilderNavigationMetadata, type AnalyticsRequestBuilder } from './analytics/';
// @ts-ignore
import { HealthRequestBuilderRequestsMetadata, type HealthRequestBuilder } from './health/';

How to reproduce

update to dotnet tool version 1.16

execute: dotnet kiota generate -d ${swaggerUrl} --language typescript --class-name ${serviceLabel}ServiceClient --exclude-backward-compatible --output ./generated-clients/${serviceName}

Open API description file

No response

Kiota Version

1.16.0+f7ce8b88eefa1c00cb6f87dd48335baac96d2cc9

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

downgrade to 1.15

Configuration

No response

Debug output

Click to expand log ```
</details>


### Other information

_No response_
@IkeOTL IkeOTL added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jul 9, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jul 9, 2024
@msgraph-bot msgraph-bot bot added the TypeScript Pull requests that update Javascript code label Jul 9, 2024
@IkeOTL IkeOTL changed the title Possible regression Possible regression in 1.16 Typescript client generation Jul 9, 2024
@baywet
Copy link
Member

baywet commented Jul 9, 2024

Hi @IkeOTL ,
Thanks for using kiota and for reaching out.
This is intentional, we've moved to generating es6 imports in #4815

You might need to update your project configuration.
Let us know if you have further questions.

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question and removed type:bug A broken experience status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jul 9, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Jul 9, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 9, 2024

In my case, in my web app I have a generated-client dir where I execute a script that simply executes kiota generate on all my target APIs, and in my web app's tsconfig the path option has the generated dir. However, my app no longer works since index.js is not found. The Kiota tool generates index.ts

Is there an option to make it generate index.js or am I misunderstanding an implicit behavior?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jul 9, 2024
@baywet
Copy link
Member

baywet commented Jul 9, 2024

can you share your tsconfig? and what's the type set to in the package.json?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jul 9, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 9, 2024

My package.json for my webapp:

{
  "name": "admin-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    ...
    "@microsoft/kiota-abstractions": "^1.0.0-preview.57",
    "@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.56",
    "@microsoft/kiota-serialization-form": "^1.0.0-preview.46",
    "@microsoft/kiota-serialization-json": "^1.0.0-preview.57",
    "@microsoft/kiota-serialization-multipart": "^1.0.0-preview.35",
    "@microsoft/kiota-serialization-text": "^1.0.0-preview.54",
    ...
  },
  "devDependencies": {
    ...
  }
}

tsconfig.json for my webapp:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"],
      "@/api-clients/*": ["./clients/generated-clients/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.js", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

Clients are used raw from kiota generate output to ./clients/generated-clients/{client-name}

Should i be updating the target to es6?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jul 9, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 9, 2024

Yes, setting it to es6 worked. Sorry about that, learned something new today.

@IkeOTL IkeOTL closed this as completed Jul 9, 2024
@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Jul 9, 2024
@baywet
Copy link
Member

baywet commented Jul 9, 2024

thanks for confirming!

@IkeOTL IkeOTL reopened this Jul 9, 2024
@github-project-automation github-project-automation bot moved this from Done ✔️ to In Progress 🚧 in Kiota Jul 9, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 9, 2024

It seems that I was mistaken... The project will not build, but VSCode can traverse the imports, so it seems I'm missing another piece.
image

where my kiota generated client looks like this:
image

and the audio/ looks like this:
image

@baywet
Copy link
Member

baywet commented Jul 9, 2024

Can you try updating your project configuration to this https://learn.microsoft.com/en-us/openapi/kiota/quickstarts/typescript#project-configuration

And set type module in your package JSON. Please?

@baywet baywet added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Jul 9, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 9, 2024

I tried earlier here are the results. I breaks my current Next.js project, as in non-Kiota client imports:
image

tsconfig.json
image

package.json
image

Interesting note, if i add .js to the end of my imports VSCode stops complaining:
image

However, build still fails:
image

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jul 9, 2024
@baywet
Copy link
Member

baywet commented Jul 10, 2024

I am not very familiar with nextJS build pipeline. My guess is es modules are not enabled in the build configuration for your project and this is why it does not recognize imports with a JS extension.
Next JS itself seems to support es modules, so make sure you have the latest version and good luck with the configuration investigation.
https://www.codeconcisely.com/posts/nextjs-esm/

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Jul 10, 2024
@IkeOTL
Copy link
Author

IkeOTL commented Jul 10, 2024

Alright, thanks for your time!

@IkeOTL IkeOTL closed this as completed Jul 10, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question TypeScript Pull requests that update Javascript code
Projects
Archived in project
Development

No branches or pull requests

2 participants