node.jsamazon-web-servicesaws-sdk-jsamazon-transcribe

AWS Transcribe client does not provide an export named 'transcribeClient'


I'm trying to integrate AWS Transcribe in my Node.JS application. AWS S3 and Polly works fine, but AWS Transcribe does not. I'm using the example code of AWS.

When I want to start a transcribe job by the AWS example code I receive the following error: The requested module './libs/transcribeClient.js' does not provide an export named 'transcribeClient'

That was also the only file where I received the error that required is not defined. I wonder why it only happens with AWS transcribe but not with the other services as well? I'm also able to start a transcribe job via the AWS CLI.

That AWS Transcribe code does not work - transcribeClient.js:

const AWS_BUCKET_NAME="X"
const AWS_REGION="eu-central-1"
const AWS_ACCESS_KEY="XXX"
const AWS_SECRET_KEY="XXX"

// snippet-start:[transcribe.JavaScript.createclientv3]
const { TranscribeClient } = require('@aws-sdk/client-transcribe');
// Create anAmazon EC2 service client object.
const transcribeClient = new TranscribeClient({ AWS_REGION, AWS_ACCESS_KEY, AWS_SECRET_KEY });
module.exports = { transcribeClient };

That AWS Polly code works - pollyClient.js:

const AWS_BUCKET_NAME="X"
const AWS_REGION="eu-central-1"
const AWS_ACCESS_KEY="XXX"
const AWS_SECRET_KEY="XXX"

// snippet-start:[polly.JavaScript.createclientv3]
const { PollyClient } =require( "@aws-sdk/client-polly");
// Create an Amazon S3 service client object.
const pollyClient = new PollyClient({ AWS_REGION, AWS_ACCESS_KEY, AWS_SECRET_KEY});
module.exports = { pollyClient };

I'm looking forward to reading from you! Thanks!


Solution

  • I solved it. Now it's working with my Node.js 12 environment.

    package.json
    I changed "type": "modules" to "type": "commonjs".

    transcribeClient.js needs to look like this:
    Here I changed export to module.exports.

    const { TranscribeClient } = require("@aws-sdk/client-transcribe");
    const transcribeClient = new TranscribeClient({ AWS_REGION, AWS_ACCESS_KEY, AWS_SECRET_KEY});
    module.exports = { transcribeClient };
    

    transcribe_create_job.js needs to look like this:
    Here I changed the import statement to require.

    const { StartTranscriptionJobCommand } = require("@aws-sdk/client-transcribe");
    const { transcribeClient } = require("./libs/transcribeClient.js")
    
    // Set the parameters
    const params = {
      TranscriptionJobName: "test123",
      LanguageCode: "en-GB", // For example, 'en-US'
      MediaFormat: "webm", // For example, 'wav'
      Media: {
        MediaFileUri: "https://x.s3.eu-central-1.amazonaws.com/dlpasiddi.webm",
      },
    };
    
    const run = async () => {
      try {
        const data = await transcribeClient.send(
          new StartTranscriptionJobCommand(params)
        );
        console.log("Success - put", data);
        return data; // For unit tests.
      } catch (err) {
        console.log("Error", err);
      }
    };
    run();