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

Error with ESM support when using the openai package #4277

Open
dyarleniber opened this issue May 2, 2024 · 0 comments
Open

Error with ESM support when using the openai package #4277

dyarleniber opened this issue May 2, 2024 · 0 comments

Comments

@dyarleniber
Copy link

When running a Node.js (v20) server with ESM modules using dd-trace and openai packages, the process crashes with the following error:

➜  dd-trace-openai-nodejs-example git:(main) node --env-file=.env --import dd-trace/register.js index.js
file:///Users/admin/workspace/personal/dd-trace-openai-nodejs-example/node_modules/openai/resources/index.mjs?iitm=true:72
    let $Completions = namespace.Completions
        ^

SyntaxError: Identifier '$Completions' has already been declared
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:167:18)
    at callTranslator (node:internal/modules/esm/loader:285:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:30)

Node.js v20.11.0

Expected Behavior

Running node --import dd-trace/register.js index.js should start the server without crashing.

Steps to Reproduce

The following repository contains the code to reproduce the issue: dd-trace-openai-nodejs-example.

Using Node.js v20.11.0:

  1. Run npm init -y
  2. Run npm i dd-trace@5.12.0 openai@4.40.0
  3. Add to the package.json file:
{
  "type": "module"
}
  1. Import dd-trace and openai in the index.js file:
import dataDogTracer from "dd-trace";
import OpenAI from "openai";

dataDogTracer.init({
  logInjection: true,
  runtimeMetrics: true,
});

const openAIClient = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

...
  1. Run node --import dd-trace/register.js index.js

The following repository contains the code to reproduce the issue: dd-trace-openai-nodejs-example.

Your Environment

  • Node.js: 20.11.0
  • dd-trace: 5.12.0
  • openai: 4.40.0
  • OS: macOS Sonoma 14.4.1
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

1 participant