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

Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher. #1992

Open
sagardwivedi opened this issue Jan 21, 2024 · 22 comments
Assignees

Comments

@sagardwivedi
Copy link

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

image

@danilofuchs
Copy link

This seems like a Typescript configuration issue on your side. Please check if your tsconfig with target ES2022 includes the generated folder

@sagardwivedi
Copy link
Author

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.

@astromme
Copy link

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?

@willtpwise
Copy link

willtpwise commented Feb 16, 2024

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"

@sagardwivedi
Copy link
Author

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.

@astromme
Copy link

astromme commented Feb 16, 2024

Good to know. I also decided to switch to an alternative: https://openapi-generator.tech/ which worked better with FastAPI + NextJS

@staklau
Copy link

staklau commented Mar 2, 2024

Would love for this to be reopened as it's still an issue if you don't want to change to another library.

@sagardwivedi
Copy link
Author

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.

@sagardwivedi sagardwivedi reopened this Mar 7, 2024
@mrlubos
Copy link
Collaborator

mrlubos commented Mar 7, 2024

Anyone able to post a CodeSandbox link? If I can reproduce it, I'll fix it

@valentin-harrang
Copy link

valentin-harrang commented Mar 28, 2024

@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.

image

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;

@mrlubos
Copy link
Collaborator

mrlubos commented Mar 28, 2024

cc @jordanshatford

@jordanshatford
Copy link

@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

@valentin-harrang
Copy link

@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. 😊

@jordanshatford
Copy link

@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

@valentin-harrang
Copy link

@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

@valentin-harrang
Copy link

@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)

@jordanshatford
Copy link

@valentin-harrang thanks for testing that. I should have some time later today to check it out and figure out what’s causing it.

@valentin-harrang
Copy link

@jordanshatford thank you so much :)

@jordanshatford
Copy link

jordanshatford commented Mar 28, 2024

@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

@jordanshatford
Copy link

@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 #.

@jordanshatford
Copy link

jordanshatford commented Mar 29, 2024

@valentin-harrang this has been fixed in v0.31.0 of @hey-api/openapi-ts

@valentin-harrang
Copy link

@jordanshatford Thank you very much for your work and your responsiveness. I've just updated the package and it works perfectly ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants