alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 737 forks source link

'Hello world' template example crashes at Lambda start because of Runtime.ImportModuleError #621

Closed ThomasVuillaume closed 4 years ago

ThomasVuillaume commented 4 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

I retrieved the latest version of the ask-cli (2.2.0) and I was trying to give a try on a fresh example. I chose the ask new command with the Hello World template, with the CloudFormation option. Then, I do nothing more than ask deploy which indeed deploys everything to AWS (I can see the Lambda) and Alexa (I can see the skill). When I run the ask dialog --locale en-US command, and then demand to open hello world, and error is prompted.

See the full log below.

Expected Behavior

Well, that it works like in the tutorial.

Current Behavior

The lambda (runtime : Node.js 12.x, but I tried 10.x with same result) seems to direct-crash at startup, and it's because of this error (which I see in the CloudWatch). Aparently, some data are not found from ask-sdk-runtime

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module './dispatcher/error/mapper/GenericErrorMapper'\nRequire stack:\n- /var/task/node_modules/ask-sdk-runtime/dist/index.js\n- /var/task/node_modules/ask-sdk-core/dist/attributes/AttributesManagerFactory.js\n- /var/task/node_modules/ask-sdk-core/dist/index.js\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module './dispatcher/error/mapper/GenericErrorMapper'",
    "Require stack:",
    "- /var/task/node_modules/ask-sdk-runtime/dist/index.js",
    "- /var/task/node_modules/ask-sdk-core/dist/attributes/AttributesManagerFactory.js",
    "- /var/task/node_modules/ask-sdk-core/dist/index.js",
    "- /var/task/index.js",
    "- /var/runtime/UserFunction.js",
    "- /var/runtime/index.js",
    "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1158:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)",
    "    at Module.load (internal/modules/cjs/loader.js:1002:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:901:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)",
    "    at internal/main/run_main_module.js:18:47"
  ]
}

Also, I retrived the .zip file on the S3 bucket declared in the CloudFormation, that is used for the Lambda : it contains a full node_module folder, including the file in node_modules\ask-sdk-runtime\dist\dispatcher\error\mapper ...

Possible Solution

No idea...

Steps to Reproduce (for bugs)

$ ask -V
2.2.0
$ ask new
Please follow the wizard to start your Alexa skill project ->
? Choose the programming language you will use to code your skill:  NodeJS
? Choose a method to host your skill's backend resources:  AWS with CloudFormation
  Host your skill code with AWS services and provision with AWS CloudFormation (requires AWS account)
? Choose a template to start with:  Hello world             Alexa's hello world skill to send the greetings to the world!
? Please type in your skill name:  skill-sample-nodejs-hello-world
? Please type in your folder name for the skill project (alphanumeric):  Helloworld
Project for skill "skill-sample-nodejs-hello-world" is successfully created at C:\Users\XXXXXX\Documents\personalprojects\Helloworld

Project initialized with deploy delegate "@ask-cli/cfn-deployer" successfully.

$ cd Helloworld/

$ ask deploy
==================== Deploy Skill Metadata ====================
Skill package deployed successfully.
Skill ID: amzn1.ask.skill.XXXXXXXXXXXXXXXXXXXXXXXXXX

==================== Build Skill Code ====================
npm WARN hello-world@1.1.0 No repository field.

Skill code built successfully.
Code for region default built to C:\Users\XXXXXX\Documents\personalprojects\Helloworld\.ask\lambda\build.zip successfully with build flow nodejs-npm.

==================== Deploy Skill Infrastructure ====================
  √ Deploy Alexa skill infrastructure for region "default"
  The api endpoints of skill.json have been updated from the skill infrastructure deploy results.
Skill infrastructures deployed successfully through @ask-cli/cfn-deployer.

==================== Enable Skill ====================
Skill is enabled successfully.

$ ask dialog --locale en-US

============================================================================================================= Welcome to ASK Dialog ============================================================================================================================================================================================= In interactive mode, type your utterance text onto the console and hit enter ============================================================================================================================================================================ Alexa will then evaluate your input and give a response! ================================================================================================================================================================ Use ".record <fileName>" or ".record <fileName> --append-quit" to save list of utterances to a file. ========================================================================================================================================================== You can exit the interactive mode by entering ".quit" or "ctrl + c". =====================================================================================

User  > open hello world
[Error]: Request to skill endpoint resulted in an error.
User  >
=================================================================================================================== Goodbye! ===================================================================================================================

Context

Just trying to create a new test project, based on a provided template example, then do nothing more and just try to deploy it.

Your Environment

Node.js and NPM Info

More interesting info : the package-lock.json file generated in the .ask folder is the following :

{
  "name": "hello-world",
  "version": "1.1.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "ask-sdk-core": {
      "version": "2.8.0",
      "resolved": "https://registry.npmjs.org/ask-sdk-core/-/ask-sdk-core-2.8.0.tgz",
      "integrity": "sha512-yW5D+5Z8sKOAm/vVySTZkj7f1+LemBsOAjTEZQTK4MdS8Lp8xteg3cmuqcvCp3M8405K2LYd7TknCoEAs82HEA==",
      "requires": {
        "ask-sdk-runtime": "^2.8.0"
      }
    },
    "ask-sdk-model": {
      "version": "1.28.0",
      "resolved": "https://registry.npmjs.org/ask-sdk-model/-/ask-sdk-model-1.28.0.tgz",
      "integrity": "sha512-T4qz/hbXlQ8t6XvJBB7+tkYxpLe9/Ic+MEWNYGKgwbWnIOi5SKpfkXTEvV/mOEMpLMKj8WC84j+nRAyVc63NXQ=="
    },
    "ask-sdk-runtime": {
      "version": "2.8.0",
      "resolved": "https://registry.npmjs.org/ask-sdk-runtime/-/ask-sdk-runtime-2.8.0.tgz",
      "integrity": "sha512-hsVDcFKcbuj2H7MuAUlW0RBCTF8QOXfVCsrWSIgV2ABi8+PyI0zGUe8TdkQOGsPrDAv1PIzOS42QYqxWwPsp2g=="
    },
    "aws-sdk": {
      "version": "2.666.0",
      "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.666.0.tgz",
      "integrity": "sha512-m4m4eHs/F7SRW0OnvxRWyrAyqcQE7kyVnfwyrhA7P0w92FOmmu+tw6JKI5LZNVBsaj2VBAfPn72V6nWzP3IIlw==",
      "requires": {
        "buffer": "4.9.1",
        "events": "1.1.1",
        "ieee754": "1.1.13",
        "jmespath": "0.15.0",
        "querystring": "0.2.0",
        "sax": "1.2.1",
        "url": "0.10.3",
        "uuid": "3.3.2",
        "xml2js": "0.4.19"
      }
    },
    "base64-js": {
      "version": "1.3.1",
      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
      "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
    },
    "buffer": {
      "version": "4.9.1",
      "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
      "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
      "requires": {
        "base64-js": "^1.0.2",
        "ieee754": "^1.1.4",
        "isarray": "^1.0.0"
      }
    },
    "events": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
      "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ="
    },
    "ieee754": {
      "version": "1.1.13",
      "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
      "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
    },
    "isarray": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
      "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
    },
    "jmespath": {
      "version": "0.15.0",
      "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
      "integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc="
    },
    "punycode": {
      "version": "1.3.2",
      "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
      "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0="
    },
    "querystring": {
      "version": "0.2.0",
      "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
      "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
    },
    "sax": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
      "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o="
    },
    "url": {
      "version": "0.10.3",
      "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
      "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=",
      "requires": {
        "punycode": "1.3.2",
        "querystring": "0.2.0"
      }
    },
    "uuid": {
      "version": "3.3.2",
      "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
      "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
    },
    "xml2js": {
      "version": "0.4.19",
      "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
      "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
      "requires": {
        "sax": ">=0.6.0",
        "xmlbuilder": "~9.0.1"
      }
    },
    "xmlbuilder": {
      "version": "9.0.7",
      "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
      "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
    }
  }
}
ThomasVuillaume commented 4 years ago

Turned out it was an ask-cli related problem, caused by a failing Powershell module during Zip file construction ... All info (for unfortunate Windows users like me) are there : https://github.com/alexa/ask-cli/blob/develop/docs/FAQ.md#q-for-windows-users-if-your-skill-return-empty-response-and-log-shows-module-not-found-genericerrormapper-or-cannot-find-module-dispatchererrormappergenericerrormapper-how-to-resolve