openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher.
Describe the bug
I have "target": "ES2022"
then also i am getting Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher.
.
I am using NextJS
This seems like a Typescript configuration issue on your side. Please check if your tsconfig with target ES2022 includes the generated folder
I had set "target": "ES2022"
, but still encountered the same error. I removed the client generation and am now using it in the normal way.
I'm also experiencing this issue when using npm run build
in a Next.JS project.
@sagardwivedi can you share more about what you changed to make it work?
Same here
Using the default next.js configuration from a brand new next.js app. I've also tried ES2022 and the same issue appears
{
"compilerOptions": {
"target": "es2017",
"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/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher.
24 |
25 | export class CancelablePromise<T> implements Promise<T> {
> 26 | #isResolved: boolean;
"next": "14.1.0",
"openapi-typescript-codegen": "^0.27.0",
"typescript": "^5"
I'm also experiencing this issue when using
npm run build
in a Next.JS project.@sagardwivedi can you share more about what you changed to make it work?
I attempted to integrate FastAPI and Next.js for practice, but faced challenges and couldn't find satisfactory solutions. Consequently, I decided to switch to Supabase. That's why I closed the issue, not because I found a solution.
Good to know. I also decided to switch to an alternative: https://openapi-generator.tech/ which worked better with FastAPI + NextJS
Would love for this to be reopened as it's still an issue if you don't want to change to another library.
Would love for this to be reopened as it's still an issue if you don't want to change to another library.
No Problem. I will reopen.
Anyone able to post a CodeSandbox link? If I can reproduce it, I'll fix it
@sagardwivedi I have the same problem. Have you fixed your problem?
I use Next.js 14 with TypeScript and I tried to exclude src/types/generated
directory by adding this line is tsconfig.json
file:
"exclude":["node_modules","src/types/generated/**/*.ts"]
but I still get the error when I run npm run build
or npx tsc
.
To temporarily fix the problem I added @ts-ignore but it's not ideal, I shouldn't have to do that.
// @ts-ignore
#isResolved: boolean;
// @ts-ignore
#isRejected: boolean;
// @ts-ignore
#isCancelled: boolean;
// @ts-ignore
readonly #cancelHandlers: (() => void)[];
// @ts-ignore
readonly #promise: Promise<T>;
// @ts-ignore
#resolve?: (value: T | PromiseLike<T>) => void;
// @ts-ignore
#reject?: (reason?: any) => void;
cc @jordanshatford
@valentin-harrang are you able to share a link to the repository? I can look into this. Check out our form that is more actively maintained if you’d like https://github.com/hey-api/openapi-ts
@jordanshatford thank you for the answer. Unfortunately I can't share the repository, which is a private repository on the Gitlab of the company that employs me. Unfortunately I'm not authorised, but I can share some code files with you if you want. 😊
@valentin-harrang if possible the next config file and your tsconfig. The issue likely tracks back to the tsconfig values so I just want to replicate it
@jordanshatford Here are some additional elements:
tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./src",
"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": {
"@/*": ["./*"],
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
next.config.mjs:
import createNextIntlPlugin from "next-intl/plugin";
import ms from "ms";
const withNextIntl = createNextIntlPlugin("./src/config/i18n.ts");
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'loremflickr.com',
},
],
},
headers() {
return [
{
source: "/((?!_next|favicon.ico).*)",
missing: [
{
type: "header",
key: "Next-Router-Prefetch",
},
],
headers: [
{
key: "Cache-Control",
value: [
`s-maxage=` + ms("1d") / 1000,
`stale-while-revalidate=` + ms("1y") / 1000,
].join(", "),
},
],
},
];
},
output: "standalone", // For self-hosting in a Docker container.
transpilePackages: ["lucide-react"],
};
export default withNextIntl(nextConfig);
I added this script int package.json
:
"codegen": "openapi --input ./openapi.json --output ./src/types/generated",
And I run the script with : npm run codegen
Versions:
Next.js: 14.1.3 openapi-typescript-codegen: 0.28.0 typescript: 5.4.2
@jordanshatford I tried to generate my types thanks to https://github.com/hey-api/openapi-ts but I have the same problem in same file (CancelablePromise.ts
)
@valentin-harrang thanks for testing that. I should have some time later today to check it out and figure out what’s causing it.
@jordanshatford thank you so much :)
@valentin-harrang Try settings "target": "ES6",
(or "target": "ES2015"
) in your tsconfig. I also found that replacing #isResolved
with private isResolved
(same for all other fields) fixes the problem, however I do not know if we want to make that change in the package. see for info.
I am discussing with the other maintainer to get his input.
NOTE: you can specific a more latest target, but those are the minimum
@valentin-harrang Update: we are going to fix the issue in our repository. we dont see any issues converting those values to private instead of #
.
@valentin-harrang this has been fixed in v0.31.0 of @hey-api/openapi-ts
@jordanshatford Thank you very much for your work and your responsiveness. I've just updated the package and it works perfectly ❤️