sst
sst copied to clipboard
Error testing the WebSockets example: ReferenceError: require is not defined
Any advice about how to fix this error?
Versions
% npm -v
8.3.1
% node -v
v16.14.0
Reference
https://serverless-stack.com/examples/how-to-create-a-websocket-api-with-serverless.html
Test
wscat -c wss://xxxxxxxx.execute-api.us-east-1.amazonaws.com/websocket-dev
Trace
==========================
Starting Live Lambda Dev
==========================
SST Console: https://console.serverless-stack.com/websocket/fabio-dev/local
Debug session started. Listening for requests...
1ad1b7b3-480d-49ef-921a-060974b1411b
REQUEST fabio-dev-websocket-my-stack-Apiconnect6ADFCB1F-Fa8V1zRdscef
[src/connect.main] invoked
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:///Users/fabio/websocket/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)","
at process.emit (node:events:520:28)","
at emit (node:internal/process/promises:133:20)","
at processPromiseRejections (node:internal/process/promises:260:27)","
at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
If I follow this post advice https://stackoverflow.com/questions/31931614/require-is-not-defined-node-js by
- editing the file
node_modules/@serverless-stack/aws-lambda-ric/package.json - removing the "type": "module" line
- and testing again
a different error is raised:
node_modules/@serverless-stack/aws-lambda-ric/bin/index.js:4
import * as lambda from "../lib/index.js";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1032:15)
at Module._compile (node:internal/modules/cjs/loader:1067:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
having the same issue here, I end up installing aws-lambda-ric
@fabiolnm @JonSun30 we managed to track down the issue. @thdxr is on this!
This is fixed in 0.65.6