Upgrading JS SDK Azure blob storage gives error

Vasile 20 Reputation points
2025-08-22T09:26:30.8066667+00:00

Hello, i periodicaly update my project deps and i upgraded the @azure/storage-blob package.

Was before update

    "@azure/identity": "^4.10.2",
    "@azure/storage-blob": "^12.27.0",

After update

 "@azure/identity": "^4.11.1",
 "@azure/storage-blob": "^12.28.0",

My code:

  async getSaSToken(blobName: string): Promise<string> {
    const { startTime, expirationTime, userDelegationKey } =
      await this.getUserDelegationKey(this.THIRTY_MINUTES);

    const sasOptions: BlobSASSignatureValues = {
      blobName,
      containerName: BlobContainerNamesEnum.UPLOADS,
      permissions: BlobSASPermissions.parse('r'),
      protocol: SASProtocol.Https,
      startsOn: startTime,
      expiresOn: expirationTime,
    };

    const sasToken = generateBlobSASQueryParameters(
      sasOptions,
      userDelegationKey,
      this.storageAccountConfig.name,
    ).toString();

    return `${this.blobStorageUrl}/${BlobContainerNamesEnum.UPLOADS}/${blobName}?${sasToken}`;
  }


  private async getUserDelegationKey(liveDuration: number): Promise<{
    startTime: Date;
    expirationTime: Date;
    userDelegationKey: ServiceGetUserDelegationKeyResponse;
  }> {
    const NOW = new Date();
    const startTime = new Date(NOW.valueOf() - this.TEN_MINUTES);
    const expirationTime = new Date(NOW.valueOf() + liveDuration);

    const userDelegationKey: ServiceGetUserDelegationKeyResponse =
      await this.blobServiceClient
        .getUserDelegationKey(startTime, expirationTime)
        .catch((error) => {
          this.logger.error(error, error.stack);
          throw new InternalServerErrorException();
        });

    console.log(userDelegationKey);

    return { startTime, expirationTime, userDelegationKey };
  }

Error itself:

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined at Function.from (node:buffer:322:9) at new UserDelegationKeyCredential (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/credentials/UserDelegationKeyCredential.ts:37:23) at generateBlobSASQueryParametersInternal (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:341:35) at generateBlobSASQueryParameters (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:320:10) at BlobStorageService.getSaSToken (/media/vasile/tt/tech-titans/chat-backend/src/core/blob-storage/blob.storage.service.ts:124:52)

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 24,096 Reputation points Volunteer Moderator
    2025-08-25T13:47:24.6866667+00:00

    Hello Vasile,

    Issue:

    Customer upgrading JS SDK Azure blob storage gives error

    Error Message:

    TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined at Function.from (node:buffer:322:9) at new UserDelegationKeyCredential (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/credentials/UserDelegationKeyCredential.ts:37:23) at generateBlobSASQueryParametersInternal (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:341:35) at generateBlobSASQueryParameters (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:320:10) at BlobStorageService.getSaSToken (/media/vasile/tt/tech-titans/chat-backend/src/core/blob-storage/blob.storage.service.ts:124:52)

    Solution:

    Customer confirmed the problem was not in permissions and found the solution on github here

    PS: The github issue fix is in deleting yarn.lock file and node_modules folder!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.