Monday, 10 June 2019

GraphQL query in NodeJS returns AWS CloudWatch error "Unable to import module 'index'"

The below GraphQL request is based on this tutorial and the Alexa NodeJS HelloWorld boilerplate. After running the invocation name Alexa returns "There was a problem with the requested skill's response". The skill is custom + Alexa hosted.

AWS CloudWatch Log:

START RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598 Version: 13
Unable to import module 'index': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/index.js:6:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
END RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598

NodeJS Code:

 const Alexa = require('ask-sdk-core');
    const { GraphQLClient } = require('graphql-request');
    const GRAPHQL_ENDPOINT = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr';
    const graphQLClient = new GraphQLClient(GRAPHQL_ENDPOINT, { })
    const helloWorldQuery = `
        {
          Movie(title: "Inception") {
            releaseDate
            actors {
              name
            }
          }
        }
      `

    const LaunchRequestHandler = {
      canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
      },
      handle(handlerInput) {
        const speechText = 'Welcome to the Alexa Skills Kit, you can say hello!';

        return handlerInput.responseBuilder
          .speak(speechText)
          .reprompt(speechText)
          .withSimpleCard('Hello World', speechText)
          .getResponse();
      },
    };

    const HelloWorldIntentHandler = {
     canHandle(handlerInput) {
     return (
          handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent'
        );
      },
     async handle(handlerInput) {
     const response = await graphQLClient.request(helloWorldQuery);

     const speechText = `Hello World ${response}`;

     return handlerInput.responseBuilder
     .speak(speechText)
     // .withSimpleCard('GraphQL Query', speechText)
          .getResponse();
      },
    };

How to fix this error?



from GraphQL query in NodeJS returns AWS CloudWatch error "Unable to import module 'index'"

No comments:

Post a Comment