1
votes

I am working on AWS Lambda using nodeJS and have aws-sdk & nanoid-good dependencies in my code. I am facing issue and unable to test my lambda code and getting error which states

"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'nanoid-good/generate'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module 'nanoid-good/generate'", "Require stack:", "- /var/task/index.js", "- /var/runtime/UserFunction.js",

const AWS = require('aws-sdk');
AWS.config.logger = console;
const dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' });
const ses = new AWS.SES({ apiVersion: '2010-12-01' });
var en = require("nanoid-good/locale/en");
var generate = require("nanoid-good/generate")(en);

Unable to figure out and what needs to be done to solve it. I am using Visual Studio and terminal to locally install the dependencies and create the zip and then upload the code to AWS Lambda.

Any assistance will be appreciated. Thank you

1
Please can you try this import 'var generate = require("nanoid-good/generate").nanoid(en);' rather then you have used in ur mention code. - Abdul Moeez
Thanks for the reply. I did try what you mentioned but getting the same error - Ankit

1 Answers

0
votes

Please can you try this import:

const AWS = require('aws-sdk');
AWS.config.logger = console;

const dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' });
const ses = new AWS.SES({ apiVersion: '2010-12-01' });

var en = require("nanoid-good/locale/en");
var generate = require("nanoid-good/generate").nanoid(en);

Documentation: https://www.npmjs.com/package/nanoid-good