Problem with StandardSkillBuilder: "Alexa.SkillBuilders.standard is not a function" error log

106 Views Asked by At

Alright. So this is my very first post here on StackOverflow, so please don't kill me if any information to reproduce my problem is missing. I really try to be precise.

So I'm just about to learn how to develop alexa skills. I watched some tutorials and cloned example code from github. As my skill serves the purpose of conducting a spoken user study, it should ask participants questions and save given answers in a database.

To save participants' responses, I thought of using DynamoDB as a data storage as a "default table" is provided for every Alexa-hosted skill inherently. Subsequently, I tried to set up the DynamoDbPersistenceAdapter according to https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-session-persistence.html. The dcoumentation suggests using the CustomSkillBuilder:

exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandler(
    //all handlers
    )
    .addErrorHandlers(
    //error handlers
    )
    .withPersistenceAdpater(
        new ddBAdapter.DynamoDbPersistenceAdapter({
            tableName: process.env.DYNAMODB_PERSISTENCE_TABLE_NAME,
            createTable: false,
            dynamoDBClient: new AWS.DynamoDB({apiVersion: 'latest', region: process.env.DYNAMODB_PERSISTENCE_REGION})
        })
    )

Besides, I did find out, that when using Alexa-hosted skills, configuring their "default table", e.g. with a custom table name or partition key, is not possible due to limited access with an VoiceHubSSORole. Creating a new table or adjusting the mentioned one is not allowed (see: https://amazon.developer.forums.answerhub.com/questions/234700/access-to-aws-console-from-alexa-developer-console.html?childToView=234908#answer-234908).

For this reason, I wanted to play around with other options such as the use of StandardSkillBuilder rather than CustomSkillBuilder. Looking into the documentation (https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/construct-skill-instance.html#skill-builders), the StandardSkillBuilder should be created by:

const standardSkillBuilder = Alexa.SkillBuilders.standard();

But here's the problem: When deploying my skill and running it, an error is thrown by exactly that line of code, saying: "Alexa.SkillBuilder.standard is not a function":

2023-09-13T12:56:20.883Z    undefined   ERROR   Uncaught Exception  
{
    "errorType": "TypeError",
    "errorMessage": "Alexa.SkillBuilders.standard is not a function",
    "stack": [
        "TypeError: Alexa.SkillBuilders.standard is not a function",
        "    at Object.<anonymous> (/var/task/index.js:208:39)",
        "    at Module._compile (node:internal/modules/cjs/loader:1198:14)",
        "    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1076:32)",
        "    at Function.Module._load (node:internal/modules/cjs/loader:911:12)",
        "    at Module.require (node:internal/modules/cjs/loader:1100:19)",
        "    at require (node:internal/modules/cjs/helpers:119:18)",
        "    at _tryRequireFile (file:///var/runtime/index.mjs:976:37)",
        "    at _tryRequire (file:///var/runtime/index.mjs:1026:25)",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1055:22)"
    ]
}

So my question is: Did I miss something here? Is the StandardSkillBuilder somehow deprecated? Or do I need to configure it differently in my code rather than with const standardSkillBuilder = Alexa.SkillBuilders.standard() ?

Please check also: http://ask-sdk-node-typedoc.s3-website-us-east-1.amazonaws.com/interfaces/standardskillbuilder.html

My dependencies: "ask-sdk": "^2.14.0", "ask-sdk-core": "^2.7.0", "ask-sdk-dynamodb-persistence-adapter": "^2.14.0", "ask-sdk-model": "^1.86.0", "aws-sdk": "^2.326.0"

My steps of action:

I tried using the CustomSkillBuilder as in the documentation https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-session-persistence.html. Everything worked fine and persistent attributes got saved in the dynamoDB which is provided automatically when creating an Alexa-hosted skill.

Then, I tried changing the line of code where my skill builder is defined according to https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/construct-skill-instance.html#skill-builders. I expected that methods like withTableName(), withAutoCreateTable(), ... would now be available, but my code does not pass the line const standardSkillBuilder = Alexa.SkillBuilders.standard() without errors

1

There are 1 best solutions below

0
On

If the purpose of using StandardSkillBuilder is to create or change the table name, or the partition key of the DynamoDB table provided with an Alexa-hosted skill, you should know that this is not possible. You can only use the table as it is, regardless of whether you use CustomSkillBuilder or StandardSkillBuilder.

In addition, the error you are getting is thrown because the "ask-sdk” dependency is included in the package.json but it’s not imported in the index.js file. So, if you want to avoid that error you need to include the following line in index.js:

const Alexa = require('ask-sdk')

If, instead, you need to customise your table or create new ones, you have to use your personal AWS account. For more details about how to use personal AWS resources with your Alexa-hosted skill, you can see the following documentation: https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html