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

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

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