Skip to content

OpenAI SDK Warning: 'this' Undefined at Top Level of ES Module with Nuxt and Bun #1394

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

Open
1 task done
hermesalvesbr opened this issue Mar 19, 2025 · 3 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@hermesalvesbr
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

I’ve encountered the following warning in my project when using the OpenAI TypeScript SDK:

[7:39:29 AM] WARN node_modules/openai/lib/AbstractChatCompletionRunner.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

My project dependencies are:

"openai": "^4.87.4"
"nuxt": "^3.16.0"

I’m running the project with:

bun --version 1.2.5
node --version v22.2.0

It seems to be related to how the OpenAI SDK is handling ES modules, possibly due to a compatibility issue with my setup. Has anyone experienced this warning, and how can I resolve it?"

To Reproduce

Steps to reproduce the behavior:

Set up a Nuxt project with "nuxt": "^3.16.0".
Install the OpenAI SDK with "openai": "^4.87.4".
Configure the Nuxt server API to integrate with OpenAI (e.g., using the OpenAI SDK in a server route or API endpoint).
Run nuxt dev using either:
    Node.js version 22.2.0, or
    Bun version 1.2.5.
Observe the console output during development.

Expected Behavior: No warnings should appear in the console.

Actual Behavior: The following warning repeats dozens of times in the console:
WARN node_modules/openai/lib/AbstractChatCompletionRunner.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

Code snippets

OS

Windows WSL and Ubuntu Server

Node version

Node 22

Library version

Openai 4.87.4

@hermesalvesbr hermesalvesbr added the bug Something isn't working label Mar 19, 2025
@RobertCraigie
Copy link
Collaborator

Thanks for the report, do you also see this warning using the 5.0.0-beta.0 version?

@hermesalvesbr
Copy link
Author

The problem persists in bun and also in node 22.

 bun update
[0.45ms] ".env"
bun update v1.2.5 (013fdddc)

$ nuxt prepare && bun run build:icons
✔ Types generated in .nuxt                                                       nuxi  8:10:36 AM
$ tsx plugins/iconify/build-icons.ts
Saved CSS to /home/hermes/Projetos-linux/cidadeMobile/plugins/iconify/icons.css!

↑ openai 4.87.4 → 5.0.0-beta.0

2 packages installed [6.38s]
➜  cidadeMobile git:(alpha) ✗ bun dev
$ nuxt dev
Nuxt 3.16.0 with Nitro 2.11.6                                                     nuxi  8:10:47 AM
                                                                                        8:10:48 AM
  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

ℹ Re-optimizing dependencies because lockfile has changed                              8:10:49 AM
✔ Vite client built in 170ms                                                           8:10:49 AM
✔ Vite server built in 670ms                                                           8:10:50 AM

[8:10:51 AM]  WARN  node_modules/openai/client.mjs (2:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/client.mjs (2:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/client.mjs (8:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/client.mjs (8:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/api-promise.mjs (2:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/api-promise.mjs (2:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/api-promise.mjs (8:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/api-promise.mjs (8:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/pagination.mjs (2:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/pagination.mjs (2:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/pagination.mjs (8:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:51 AM]  WARN  node_modules/openai/pagination.mjs (8:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/internal/decoders/line.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/internal/decoders/line.mjs (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/internal/decoders/line.mjs (7:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/internal/decoders/line.mjs (7:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AssistantStream.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AssistantStream.mjs (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AssistantStream.mjs (6:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AssistantStream.mjs (6:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/EventStream.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/EventStream.mjs (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/EventStream.mjs (7:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/EventStream.mjs (7:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/ChatCompletionStream.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/ChatCompletionStream.mjs (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/ChatCompletionStream.mjs (7:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/ChatCompletionStream.mjs (7:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AbstractChatCompletionRunner.mjs (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten


[8:10:52 AM]  WARN  node_modules/openai/lib/AbstractChatCompletionRunner.mjs (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

✔ Nuxt Nitro server built in 1042ms                                              nitro 8:10:52 AM
ℹ Vite client warmed up in 6305ms                                                      8:10:58 AM
ℹ Vite server warmed up in 10539ms

@stainless-em
Copy link

This is standard typescript helper output, this being undefined is harmless and expected.

In openai@5 we change how typescript emits helpers to reduce bundle size, which will also remove these warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants