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

ReferenceError: Can't find variable: CN_ROOT - Bun + Couchbase #14002

Open
zx8086 opened this issue Sep 18, 2024 · 0 comments
Open

ReferenceError: Can't find variable: CN_ROOT - Bun + Couchbase #14002

zx8086 opened this issue Sep 18, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@zx8086
Copy link

zx8086 commented Sep 18, 2024

What version of Bun is running?

1.1.27

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Issue is occurring when trying to run the dockerized the Bun application. Works outside the container, but bundling the application as part of the build processes causes the error message.

What is the expected behavior?

No response

What do you see instead?

93743 |   var nodeVersionMajor = getNodeMajorVersion(nodeVersion);
93744 |   var arch = process.arch;
93745 |   var platform = process.platform;
93746 |   var libc = getLinuxType(platform);
93747 |   var sslType = getSSLType(runtime, nodeVersion);
93748 |   CN_ROOT = path2.resolve(path2.dirname(__filename), "..");
          ^
ReferenceError: Can't find variable: CN_ROOT
      at /usr/src/app/dist/index.js:93748:3
      at /usr/src/app/dist/index.js:18:47
      at /usr/src/app/dist/index.js:93919:108
      at /usr/src/app/dist/index.js:18:47
      at /usr/src/app/dist/index.js:105051:35
      at /usr/src/app/dist/index.js:18:47
      at /usr/src/app/dist/index.js:207982:32

Bun v1.1.27 (Linux arm64)

Additional information

From AI...

t
index.js.zip
he issue is originating from:

  1. File: /usr/src/app/dist/index.js
    Line: 93748
    This file is your bundled application code, which includes the Couchbase SDK. The error occurs when the code tries to assign a value to CN_ROOT, but CN_ROOT hasn't been declared.
    Given the high line number (93748) and the fact that this is in a bundled file, this code is likely part of the Couchbase SDK or one of its dependencies, not your application code directly.
    The error is happening because:
    The bundled code expects CN_ROOT to be a global variable.
    In the context where this code is running (your Bun environment in Docker), CN_ROOT is not defined as a global variable.
    This suggests that the issue is stemming from how the Couchbase SDK is being bundled and executed in your Bun environment. The SDK is written with certain assumptions about its execution environment (likely expecting to run in a standard Node.js environment), and these assumptions are not being met in your current setup.
    To resolve this, we need to either:
    Ensure CN_ROOT is defined globally before this code runs.
  2. Modify how the Couchbase SDK is bundled or included in your application.
    Use a version of the Couchbase SDK that's compatible with Bun and your bundling process.
    Given that this is happening in a bundled file, the most direct solution would be to ensure CN_ROOT is defined globally before your application starts. However, this is a bit of a hack and might lead to other issues down the line.
    A more robust solution would involve investigating how to properly integrate the Couchbase SDK with Bun, possibly by excluding it from the bundling process and loading it separately at runtime.
@zx8086 zx8086 added bug Something isn't working needs triage labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant