next.js 13 在使用 openai 4.0 包时构建时出现私有标识符错误

我在我的 next.js 应用中添加了新的 4.0 openai 包,我仅在应用的服务器端使用它,但在构建时遇到了错误。

- info Linting and checking validity of types .Failed to compile../node_modules/openai/src/core.ts:539:3Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher.  537 |  538 | export abstract class AbstractPage<Item> implements AsyncIterable<Item> {> 539 |   #client: APIClient;      |   ^  540 |   protected options: FinalRequestOptions;  541 |  542 |   protected response: Response;

我尝试将 tsconfig 的目标改为 es6、es2015、esnext,但似乎不起作用,skipLibCheck 已启用,所以我更加困惑为什么会发生这种情况

这是我的 tsconfig:

{  "compilerOptions": {    "target": "es5",    "lib": [      "dom",      "dom.iterable",      "esnext"    ],    "allowJs": true,    "skipLibCheck": true,    "strict": true,    "forceConsistentCasingInFileNames": true,    "noEmit": true,    "esModuleInterop": true,    "module": "esnext",    "moduleResolution": "node",    "resolveJsonModule": true,    "isolatedModules": true,    "jsx": "preserve",    "incremental": true,    "plugins": [      {        "name": "next"      }    ],    "paths": {      "$/*": [        "./src/*"      ],      "$app/*": [        "./src/app/*"      ],      "$cmp/*": [        "./src/components/*"      ],      "$types/*": [        "./src/types/*"      ],      "$assets/*": [        "./src/assets/*"      ],      "$lib/*": [        "./src/lib/*"      ],    }  },  "include": [    "next-env.d.ts",    "**/*.ts",    "**/*.tsx",    ".next/types/**/*.ts"  ],  "exclude": [    "node_modules"  ]}

回答:

使用这个导入(导入中没有“src”):

import { type ChatCompletionMessageParam } from "openai/resources/index.mjs";

而不是:

import { ChatCompletionMessageParam } from "openai/src/resources/chat/completions";

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注