question

iamonthienet avatar image
iamonthienet asked

TypeError: Cannot read property 'locale' of undefined

Hi!

I have a very simple Lambda function (with default and basic configuration) that is throwing the following error. Any pointers will be appreciated.

START RequestId: a846ae65-b8b3-11e6-883c-975a9154a295 Version: $LATEST
2016-12-02T17:20:44.995Z	a846ae65-b8b3-11e6-883c-975a9154a295	TypeError: Cannot read property 'locale' of undefined
    at AlexaRequestEmitter.HandleLambdaEvent (/var/task/node_modules/alexa-sdk/lib/alexa.js:102:38)
    at AlexaRequestEmitter.Object.defineProperty.value (/var/task/node_modules/alexa-sdk/lib/alexa.js:91:31)
    at exports.handler (/var/task/index.js:172:11)
END RequestId: a846ae65-b8b3-11e6-883c-975a9154a295
REPORT RequestId: a846ae65-b8b3-11e6-883c-975a9154a295	Duration: 120.88 ms	Billed Duration: 200 ms 	Memory Size: 128 MB	Max Memory Used: 27 MB	
Process exited before completing request
alexa skills kitlambdanode_js
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Brian@Amazon avatar image
Brian@Amazon answered

I see that this post has been liked. Is anyone else experiencing this issue?

Download the newest version of the alexa sdk and/or git pull! I believe this issue has been fixed.

10 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Hergert avatar image David Hergert commented ·

Figured it out. I was using the wrong Test Event data. In the Lambda interface, you have to make sure to select "Alexa Start Session" as the type. Not Hello World. smh.

9 Likes 9 ·
newuser-bf68cfaf-6cc1-4993-a0b2-a51a5d678f85 avatar image newuser-bf68cfaf-6cc1-4993-a0b2-a51a5d678f85 David Hergert commented ·

I am having the same issue and I can't find where you set Alexa Start Session can you please walk me through it?

0 Likes 0 ·
newuser-f4a70469-a1a3-4a11-afc5-7752c61c038b avatar image newuser-f4a70469-a1a3-4a11-afc5-7752c61c038b newuser-bf68cfaf-6cc1-4993-a0b2-a51a5d678f85 commented ·

For your lambda function, There is Actions button drop down, Click on it and then select Configure Test Event and then select "Alexa Start Session". In that JSON make sure that the data is filled in.

0 Likes 0 ·
Brian@Amazon avatar image Brian@Amazon ♦ David Hergert commented ·

You can also take the json out of the request in service simulator.

0 Likes 0 ·
David Hergert avatar image David Hergert commented ·

I also am seeing this issue. What's frustrating is I used the blueprint 'alexa-skill-kit-sdk-factskill' provided BY Amazon right in the Developer Portal and it doesn't even work.

So I followed this outline, https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/content/fact-skill-3 and downloaded FactSkillTemplate.zip linked on that page and tried using that and THAT gave me different error about "Cannot read property 'attributes'" of undefined. https://forums.developer.amazon.com/questions/33413/alexa-sdk-code-stopped-working-with-this-error-at.html

Any help @Brian@Amazon?

0 Likes 0 ·
GregorAdams avatar image GregorAdams commented ·

I just experienced the same issue.

I spent the entire day trying to build a lambda compatible zip. Now I get this error.

alexa-sdk is up to date.

Building skill: 10 minutes

Uploading working zip 6 hours.

Please provide better info how this works. All examples have a single file, which is not very common for usual development. It's really sad that skilled developers fail at simple tasks like these due to a lack of documentation (or tldr; documentations). Things like deploying should be explained carefully and easy to understand.

0 Likes 0 ·
Brian@Amazon avatar image Brian@Amazon ♦ GregorAdams commented ·

I'll assume you're proficient with linux command line, because this might be a good way to explain.

Let's say your main function is index.js. Put index.js in a folder, let's call it parent. While in parent use command: npm install --save alexa-sdk . This should create a node_modules folder. Then use the following command while in parent

zip -r node_modules index.js lambda.zip

lambda.zip is now your properly formatted folder.

A good explanation of this is located here, it should apply to most sklils:

https://github.com/alexa/skill-sample-nodejs-calendar-reader

0 Likes 0 ·
Wayne Smallman avatar image Wayne Smallman Brian@Amazon ♦ commented ·

I've had this problem with each attempt, both with zip files from the development tutorials and those I've created myself.

I've used the zip compression from the CLI and it's made little difference, other than eliminating some other issue, but not this latest error.

Any advice would be much appreciated.

0 Likes 0 ·
Show more comments
Show more comments
kumar avatar image
kumar answered

I had the same issues ever since I switched to alexa-sdk, I noticed that the issue does not occur when you make a call from alexa or alexa developer site. Locale from the request is used in the SDK / alexa.js

{
  "session": {
    "sessionId": "SessionId.XXXX",
    "application": {
      "applicationId": "amzn1.ask.skill.XXXXX"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.XXXXXX"
    },
    "new": true
  },
  "request": {
    "type": "IntentRequest",
    "requestId": "EdwRequestId.c44362bc-XXX",
    "locale": "en-US",
    "timestamp": "2017-04-16T19:23:07Z",
    "intent": {
      "name": "AMAZON.StopIntent",
      "slots": {}
    }
  },
  "version": "1.0"
}
2 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rvcedd avatar image rvcedd commented ·

I have exactly the same problem. If invoke the lambda handler from the Alexa developer site the function runs the code correctly as it was uploaded in the zip file. So there definitely is a problem with AWS and alexa-sdk. Do you know if there is any official way to report the problem?

Are there any other implications that might not be immediately visible that are worth considering?

0 Likes 0 ·
Brian@Amazon avatar image Brian@Amazon ♦ rvcedd commented ·

The developer site doesn't provide locale. I still haven't been able to reproduce this, however.

What happens if you copy the request from the service simulator across to your lambda test console (if your'e using lambda).

0 Likes 0 ·
Elmo avatar image
Elmo answered

Are there any updates on this. I have the same problem and no clue how to fix it. Thanks for any hint!

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jamie Grossman avatar image Jamie Grossman ♦♦ commented ·

Were you able to get around this issue? Otherwise, as this is a slightly older thread, I would suggest posting a new thread with more information specific to your query.

Regards,

Jamie

0 Likes 0 ·