https://serverless-stack.com/ logo
#help
Title
# help
t

Thomas Ankcorn

01/26/2022, 10:50 PM
Help, I updated my sst version (from a really old one) to a pretty new one and now I get this error when I invoke my lambdas
Copy code
.sst/artifacts/99a3edf9/src/lambda.handler is undefined or not exported
the code looks like this
Copy code
import SQS from 'aws-sdk/clients/sqs';

const sqs = new SQS();

// Your core application
const send = async (event) => {
  console.log(event)
  await sqs.sendMessage({
    QueueUrl: '<https://sqs.eu-west-1.amazonaws.com/260235234243/dev-scheduler-Queue>',
    MessageBody: JSON.stringify(event),
    DelaySeconds: 15
  }).promise()

  return `Hello, World!`
};

export const handler = send;
and the stack looks like this
Copy code
import * as sst from "@serverless-stack/resources";
import { TableFieldType } from "@serverless-stack/resources";

export default class MyStack extends sst.Stack {
  constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
    super(scope, id, props);

    const table = new sst.Table(this, "Table", {
      fields: {
        pk: TableFieldType.STRING,
        sk: TableFieldType.STRING,
      },
      primaryIndex: { partitionKey: "pk", sortKey: "sk" },
    });

    const queue = new sst.Queue(this, "Queue", {
      consumer: "src/queueConsumer.handler",
    });

    const cron = new sst.Cron(this, "Cron", {
      schedule: "rate(5 minutes)",
      job: {
        environment: {
          TABLE_NAME: table.tableName,
          QUEUE_URL: queue.sqsQueue.queueUrl,
        },
        permissions: [queue],
        function: "src/lambda.handler",
      }
    })

    // Show the endpoint in the output
    this.addOutputs({
      "QueueURL": queue.sqsQueue.queueUrl,
    });
  }
}
in the .sst/artifacts folder I can find this
Copy code
var handler = send;
module.exports = __toCommonJS(lambda_exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  handler
});
//# sourceMappingURL=lambda.js.map
t

thdxr

01/26/2022, 11:04 PM
let me see
what version are you on now?
t

Thomas Ankcorn

01/26/2022, 11:05 PM
0.60.6
I have copied the stack into a new sst project to see if that helps 😄 🤞
same issue
t

thdxr

01/26/2022, 11:11 PM
can you try rewriting it as
export const handler = ...
instead of aliasing it to send first
t

Thomas Ankcorn

01/26/2022, 11:15 PM
same issue, this is what the bundled js now looks like
Copy code
var handler = async (scheduleDetails) => {
  console.log(scheduleDetails);
  await sqs.sendMessage({
    QueueUrl: "<https://sqs.eu-west-1.amazonaws.com/260235234243/dev-scheduler-Queue>",
    MessageBody: JSON.stringify(scheduleDetails),
    DelaySeconds: 15
  }).promise();
  return `Hello, World!`;
};
module.exports = __toCommonJS(lambda_exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  handler
});
//# sourceMappingURL=lambda.js.map
my node version is 14.7.0 if that makes any difference
t

thdxr

01/26/2022, 11:18 PM
typescript or normal?
I tried the following
Copy code
const send = async (event) => {
  console.log("Hello World!")
}

export const handler = send
And I can't replicate
t

Thomas Ankcorn

01/26/2022, 11:20 PM
typescript, i’m testing in a new sst stack now. I think something must have got in a really weird state when I upgraded. Thanks for looking into it
brand new typescript stack has the same issue 👀, fresh deployment
t

thdxr

01/26/2022, 11:23 PM
what is in your tsconfig
t

Thomas Ankcorn

01/26/2022, 11:24 PM
just the one that is pulled down from you
Copy code
{
  "extends": "@tsconfig/node14",
  "include": [
    "stacks",
    "src"
  ]
}
I just changed my node version and it now works… 😄 😕
I am now on node 16.13
t

thdxr

01/26/2022, 11:25 PM
hm ok I'm going to have to investigate this
t

Thomas Ankcorn

01/26/2022, 11:26 PM
it prompted a reinstall for some esbuild stuff
Copy code
Preparing your SST app
The package "esbuild-darwin-arm64" could not be found, and is needed by esbuild.

If you are installing esbuild with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by esbuild to install the correct binary executable for your current platform.
npm notice 
npm notice New minor version of npm available! 8.1.2 -> 8.3.2
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.3.2>
npm notice Run npm install -g npm@8.3.2 to update!
npm notice 
➜  my-sst-app npm start
t

thdxr

01/26/2022, 11:26 PM
Copy code
target: "node14",
is what we set if not using esm
t

Thomas Ankcorn

01/26/2022, 11:26 PM
and when I reran npm i and npm start it now works
moving back to node 14.7 breaks it again
t

thdxr

01/26/2022, 11:28 PM
I just tried on node14 and it works
but I'm on v14.18.3
can you use this exact code and show me what's iny our artifact folder:
Copy code
const send = async (event) => {
  console.log("Hello World!")
}

export const handler = send
I want to compare it with mine
t

Thomas Ankcorn

01/26/2022, 11:29 PM
node v14.18.3 works for me
t

thdxr

01/26/2022, 11:30 PM
lol
t

Thomas Ankcorn

01/26/2022, 11:30 PM
js dev ftw
t

thdxr

01/26/2022, 11:30 PM
🤦🏽‍♂️
t

Thomas Ankcorn

01/26/2022, 11:30 PM
Copy code
var handler = async (event) => {
  return {
    statusCode: 200,
    headers: { "Content-Type": "text/plain" },
    body: `Hello, World! Your request was received at ${event.requestContext.time}.`
  };
};
module.exports = __toCommonJS(lambda_exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  handler
});
//# sourceMappingURL=lambda.js.map
apologies it is not exactly the same
thats 14.18.3
t

thdxr

01/26/2022, 11:30 PM
Does it not generate a bunch of meta functions like
__toCommontJs
t

Thomas Ankcorn

01/26/2022, 11:31 PM
oh yeah thats above didn’t want to dump the whole thing
hold on
t

thdxr

01/26/2022, 11:31 PM
well no worries now
I was just worried it wasn't working on node14 across the board
t

Thomas Ankcorn

01/26/2022, 11:33 PM
I don't even want to know why that specific node version is busted 😂
Thanks for the help getting it running
4 Views