Hey guys, I get this error while testing WebSocket...
# help
s
Hey guys, I get this error while testing WebSockets locally, works fine when running on lambda. I'm on v0.65.4 Thanks
Copy code
Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ReferenceError: require is not defined","reason":"ReferenceError: require is not defined","promise":{},"stack":["Runtime.UnhandledPromiseRejection: ReferenceError: require is not defined","    at process.<anonymous> (file:///home/sam/Desktop/wrs/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)","    at process.emit (node:events:394:28)","    at emit (node:internal/process/promises:136:22)","    at processPromiseRejections (node:internal/process/promises:242:25)","    at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
f
Hey @Sam, was it working before?
t
Can you show us the version of node_modules/@serverless-stack/aws-lambda-ric/package.json
s
@thdxr
@Frank I used websockets on sst for the first time today
f
@thdxr I think a couple other folks ran into the same issue https://github.com/serverless-stack/serverless-stack/issues/1395
Do you spot anything weird in the package.json?
t
no that looks right
Let me test something
@Sam do you have require statements in your code?
And are you using bundle.esm ?
s
@thdxr No, I do not have any require statements in my code. I haven't set any configuration related to bundle.esm
t
does a simple hello world function work?
s
i'll test that out, give me a few minutes
@thdxr I just tried with a fresh hello world project with one WebSocketApi and encountered the same issue
t
what is your node version?
is this specifically with the websocket api? What if you create a normal sst.Function and invoke it from the console
s
node v16.6.0 I haven't tried sst.Function, but sst.Api works fine
t
oh so this only happens with a websocket function?
can I see your stacks code
s
stacks/MyStack.js
Copy code
import * as sst from "@serverless-stack/resources";

export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const api = new sst.WebSocketApi(this, "Api", {
      accessLog: false,
      defaultFunctionProps: {
        environment: {

        },
      },
      routes: {
        $connect: "src/connect.main",
        // $disconnect: "src/disconnect.main",
        // sendmessage: "src/sendMessage.main",
      },
    });


    new sst.Function(this, "MySnsLambda", {
      handler: "src/connect.main",
    });

    // Show the endpoint in the output
    this.addOutputs({
      "ApiEndpoint": api.url,
    });
  }
}
stacks/index.js
Copy code
import MyStack from "./MyStack";

export default function main(app) {
  new MyStack(app, "my-stack");
}
src/connect.js
Copy code
export async function main(event) {
    console.log("event", event);
    return { statusCode: 200, body: "Connected" };
}
t
so it's crashing on the connect event?
if you invoke MySnsLambda it's fine?
s
@thdxr yes only for the websocket its crashing
@thdxr i did a console.log in
node_modules/@serverless-stack/aws-lambda-ric/bin/index.js
for
handler
and looks like handler path doesn't match the path in artifacts, it omits the
$connect
.sst/artifacts/localtest-my-sst-app-my-stack-Api-/src/connect.main
actual path
.sst/artifacts/localtest-my-sst-app-my-stack-Api-$connect/src/connect.main
t
This might be some issue with the dollar sign. Thanks for tracking it down I'll fix tomorrow
s
yeah thanks, if I manually remove the $connect from the path it works
t
Fixed in 65.6