Skip to content

fix(oss): use list() instead of getBucketInfo() in ensureBucket to avoid bundling issue#6833

Open
octo-patch wants to merge 1 commit into
labring:mainfrom
octo-patch:fix/issue-6552-oss-ensure-bucket
Open

fix(oss): use list() instead of getBucketInfo() in ensureBucket to avoid bundling issue#6833
octo-patch wants to merge 1 commit into
labring:mainfrom
octo-patch:fix/issue-6552-oss-ensure-bucket

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #6552

Problem

When OSS storage is configured, the application logs the following error on startup:

ReferenceError: name is not defined
    at b.createRequest (.next/server/chunks/55042.js:1:4872)
    at b.getBucketInfo (...)
    at y.ensureBucket (...)

This happens because ali-oss's getBucketInfo() internally references a variable named name in its createRequest() function. In bundled environments (Next.js webpack), this conflicts with JavaScript's implicit global name property — resulting in a ReferenceError every time the application starts with OSS configured.

The error is non-fatal (caught and logged), but confusing: users see an alarming error even though their OSS bucket exists and uploads work fine.

Solution

Replace getBucketInfo() with list({ 'max-keys': 1 }) in the ensureBucket() method of the OSS adapter. The list() call:

  • Verifies the bucket is accessible (throws on invalid credentials or missing bucket)
  • Does not trigger the name is not defined code path
  • Is already used successfully elsewhere in the OSS adapter

Testing

  • OSS configuration with valid credentials: list() returns successfully, no error logged
  • OSS configuration with invalid bucket name: list() throws an OSS NoSuchBucket error, correctly caught and logged

…oid bundling issue

When using OSS storage with Next.js, getBucketInfo() triggers
"ReferenceError: name is not defined" at startup. This happens because
the ali-oss SDK references a variable named `name` internally in its
createRequest function, which conflicts with the global `name` property
in bundled JavaScript environments.

Replacing getBucketInfo() with list({ 'max-keys': 1 }) achieves the same
goal (verifying the bucket is accessible) while avoiding the problematic
code path. The list() method is already used successfully elsewhere in
the OSS adapter.

Fixes labring#6552

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 28, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


octo-patch seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Apr 28, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


octo-patch seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown

Build Successful - Preview code-sandbox Image for this PR:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:code-sandbox_6eac7d52c13cc113c9bc5ae25cca12d4d31646a4

@github-actions
Copy link
Copy Markdown

Build Successful - Preview fastgpt Image for this PR:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fastgpt_6eac7d52c13cc113c9bc5ae25cca12d4d31646a4

@github-actions
Copy link
Copy Markdown

Build Successful - Preview mcp_server Image for this PR:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:mcp_server_6eac7d52c13cc113c9bc5ae25cca12d4d31646a4

@c121914yu c121914yu requested a review from xqvvu April 28, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oss配置之后上传附件都能成功,但是请求报错:name is not defined

1 participant