Manoel Feliciano
07/05/2021, 9:46 PMsst start
it works fine, but when I try to deploy it, it complains about an external module called ffmpeg-static. If I add this library to the externalModules property of the bundle, the deploy works, but my function does not work when I call the url, it complains about the following… (will put inside the thread).
Does anybody have a clue of what might be happening? Thanks a lot in advance!Manoel Feliciano
07/05/2021, 9:46 PM{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: AbortController is not a constructor",
"reason": {
"errorType": "TypeError",
"errorMessage": "AbortController is not a constructor",
"code": 500,
"name": "TypeError",
"method": "get",
"path": "/gateway/bot",
"stack": [
"TypeError: AbortController is not a constructor",
" at RequestHandler.execute (/var/task/lambda.js:12126:17)",
" at RequestHandler.execute (/var/task/lambda.js:12129:21)",
" at RequestHandler.push (/var/task/lambda.js:12092:27)",
" at async WebSocketManager2.connect (/var/task/lambda.js:23669:11)",
" at async Client.login (/var/task/lambda.js:24346:9)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: TypeError: AbortController is not a constructor",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
Frank
nodeModules
instead of externalModules
Manoel Feliciano
07/05/2021, 9:54 PMFrank
externalModules
are excluded from the package. Where as with nodeModules
, the modules are not bundled by esbuild, but included as in with the Lambda code.Manoel Feliciano
07/05/2021, 9:57 PMManoel Feliciano
07/05/2021, 9:57 PMsst start
though…Frank
.build
folder in your app’s directoryFrank
.build/cdk.out
?Frank
sst start
, and since ffmpeg-static
is installed locally, ur code runs fine. Where as with sst deploy
, ur code is packaged and sent to Lambda, and it’s probably not packaging ffmpeg-static
correctly, hence the error)Manoel Feliciano
07/05/2021, 10:04 PMFrank
ls
of what’s inside the cdk.out
folder?Manoel Feliciano
07/05/2021, 10:06 PMManoel Feliciano
07/05/2021, 10:07 PMtotal 152
drwxr-xr-x 8 manoelfeliciano staff 256 5 Jul 18:55 .
drwxr-xr-x 11 manoelfeliciano staff 352 5 Jul 19:05 ..
drwxr-xr-x 3 manoelfeliciano staff 96 5 Jul 18:55 .cache
drwxr-xr-x 7 manoelfeliciano staff 224 5 Jul 18:55 asset.6624c5951b2e51ab2be1a1bac1fea422e47d1aa8c12a3820d4e8514b464eeccd
-rw-r--r-- 1 manoelfeliciano staff 20 5 Jul 18:55 cdk.out
-rw-r--r-- 1 manoelfeliciano staff 35699 5 Jul 18:55 manifest.json
-rw-r--r-- 1 manoelfeliciano staff 9727 5 Jul 18:55 prod-discord-bot-discord-bot-stack.template.json
-rw-r--r-- 1 manoelfeliciano staff 23001 5 Jul 18:55 tree.json
Frank
asset.6624c5951b2e51ab2be1a1bac1fea422e47d1aa8c12a3820d4e8514b464eeccd
is the packaged Lambda code. Can you do an ls
in there?Manoel Feliciano
07/05/2021, 10:08 PMtotal 4088
drwxr-xr-x 7 manoelfeliciano staff 224 5 Jul 18:55 .
drwxr-xr-x 8 manoelfeliciano staff 256 5 Jul 18:55 ..
-rw-r--r-- 1 manoelfeliciano staff 776985 5 Jul 18:55 lambda.js
-rw-r--r-- 1 manoelfeliciano staff 1298513 5 Jul 18:55 lambda.js.map
drwxr-xr-x 26 manoelfeliciano staff 832 5 Jul 18:55 node_modules
-rw-r--r-- 1 manoelfeliciano staff 44 5 Jul 18:55 package.json
-rw-r--r-- 1 manoelfeliciano staff 6655 5 Jul 18:55 yarn.lock
Frank
nodeModules
configured, ffmpeg-static
should be packaged separately into node_modules
Frank
ls
in node_modules
?Manoel Feliciano
07/05/2021, 10:10 PM@derhuerst core-util-is inherits readable-stream
@types debug isarray safe-buffer
agent-base env-paths ms string_decoder
buffer-from ffmpeg-static parse-cache-control typedarray
caseless http-response-object process-nextick-args util-deprecate
concat-stream https-proxy-agent progress
Frank
Frank
TypeError: AbortController is not a constructor
error?Manoel Feliciano
07/05/2021, 10:12 PMsst start
.Frank
AbortController
coming from?Manoel Feliciano
07/05/2021, 10:16 PM{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: fetch is not a function",
"reason": {
"errorType": "TypeError",
"errorMessage": "fetch is not a function",
"code": 500,
"name": "TypeError",
"method": "get",
"path": "/gateway/bot",
"stack": [
"TypeError: fetch is not a function",
" at RequestHandler.execute (/var/task/lambda.js:12049:17)",
" at RequestHandler.execute (/var/task/lambda.js:12052:21)",
" at RequestHandler.push (/var/task/lambda.js:12015:27)",
" at async WebSocketManager2.connect (/var/task/lambda.js:23592:11)",
" at async Client.login (/var/task/lambda.js:24269:9)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: TypeError: fetch is not a function",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
Manoel Feliciano
07/05/2021, 10:16 PMManoel Feliciano
07/05/2021, 10:16 PMFrank
Frank
Manoel Feliciano
07/05/2021, 10:21 PMManoel Feliciano
07/05/2021, 10:44 PMconst api = new sst.Api(this, 'Api', {
defaultFunctionProps: {
bundle: {
nodeModules: ['discord.js'],
},
},
routes: {
'POST /': 'src/lambda.handler',
},
});
Needed to add the discord.js in nodeModules property inside bundle.Frank
Frank
discord.js
dynamically imports some modules internally (ie. node-fetch
, abort-controller
, etc), and these modules are not getting bundled.Frank
discord.js
as a node module, and this will ensure it and all of its dependencies are packaged with the Lambda code.