thdxr
01/18/2022, 3:19 PMMischa Spiegelmock
01/18/2022, 3:20 PMRoss Gerbasi
01/18/2022, 4:29 PMthdxr
01/18/2022, 4:37 PMRoss Gerbasi
01/18/2022, 5:04 PMexport const any = () => {
console.log('ok')
return {
statusCode: 200,
body: JSON.stringify({
msg: 'Okey Dokey',
}),
}
}
wired up like this
$default: 'handler.any',
then
npm start
When I hit that API i can see my console log but always getting a 200 and a null for the body
HTTP/1.1 200 OK
Date: Tue, 18 Jan 2022 17:03:51 GMT
Content-Type: application/json
Content-Length: 4
Connection: close
Apigw-Requestid: MJrmkg06IAMESjA=
null
Ross Gerbasi
01/18/2022, 5:04 PMRoss Gerbasi
01/18/2022, 5:15 PMGET
just to make sure its not a any problem.
'GET /': 'handler.get',
same thing. @thdxr did anything change around this? Do I need a different handler response?thdxr
01/18/2022, 5:16 PMRoss Gerbasi
01/18/2022, 5:16 PMthdxr
01/18/2022, 5:16 PMRoss Gerbasi
01/18/2022, 5:16 PMRoss Gerbasi
01/18/2022, 5:24 PM{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: Dynamic require of \"path\" is not supported",
"reason": "Error: Dynamic require of \"path\" is not supported",
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: Error: Dynamic require of \"path\" is not supported",
" at process.<anonymous> (file:///home/aphex/test-sst/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)",
" at process.emit (events.js:400:28)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:96:32)"
]
}
Ross Gerbasi
01/18/2022, 5:24 PMRoss Gerbasi
01/18/2022, 5:49 PMaws-lambda-ric
maybe a big blocker here. I can't seem to load anything that uses require at all. For example my basic handler just does
import './dep'
and dep.ts
just does
require('path')
will throw
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: Dynamic require of \"path\" is not supported",
"reason": "Error: Dynamic require of \"path\" is not supported",
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: Error: Dynamic require of \"path\" is not supported",
" at process.<anonymous> (file:///home/aphex/dev/test-sst/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)",
" at process.emit (events.js:400:28)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:96:32)"
]
}
This isn't a problem for my code, but it pretty much means I can only use a very few npm modules out there, that have gone full ESM.
I think this is the issue here. https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/22Jon Holman
01/18/2022, 5:51 PM% npx sst update 0.60.0
Updating @serverless-stack/cli to 0.60.0
Updating @serverless-stack/resources to 0.60.0
Updating @aws-cdk/aws-apigatewayv2-alpha@2.7.0-alpha.0
Updating aws-cdk-lib@2.7.0
SST: 0.60.2
CDK: 2.7.0
thdxr
01/18/2022, 5:52 PMrequire
anywherethdxr
01/18/2022, 5:53 PMRoss Gerbasi
01/18/2022, 5:55 PMtype: module
will work with a index.js of this
import JWT from 'jwt-simple'
console.log(JWT)
Ross Gerbasi
01/18/2022, 5:56 PMthdxr
01/18/2022, 5:56 PMthdxr
01/18/2022, 5:57 PMRoss Gerbasi
01/18/2022, 5:57 PMaws-lambda-ric
though, is it possible to change how it imports things?thdxr
01/18/2022, 5:57 PMRoss Gerbasi
01/18/2022, 5:57 PMthdxr
01/18/2022, 5:58 PM// This is ok
const x = require("thing")
// This is not ok
function thing() {
const x = require("thing")
}
Ross Gerbasi
01/18/2022, 5:58 PMthdxr
01/18/2022, 5:58 PMawait import("thing")
thdxr
01/18/2022, 5:59 PMRoss Gerbasi
01/18/2022, 6:00 PMRoss Gerbasi
01/18/2022, 6:00 PMthdxr
01/18/2022, 6:01 PMthdxr
01/18/2022, 6:01 PMRoss Gerbasi
01/18/2022, 6:04 PMthdxr
01/18/2022, 6:05 PMRoss Gerbasi
01/18/2022, 6:06 PMRoss Gerbasi
01/18/2022, 6:07 PMRoss Gerbasi
01/18/2022, 6:07 PMvar require_jwt = __commonJS({
"node_modules/jwt-simple/lib/jwt.js"(exports, module) {
var crypto = __require("crypto");
var algorithmMap = {
HS256: "sha256",
HS384: "sha384",
HS512: "sha512",
RS256: "RSA-SHA256"
};
var typeMap = {
HS256: "hmac",
HS384: "hmac",
HS512: "hmac",
RS256: "sign"
};
thdxr
01/18/2022, 6:10 PMbundle.nodeModules
Ross Gerbasi
01/18/2022, 6:15 PMRoss Gerbasi
01/18/2022, 6:16 PMimport "jwt-simple";
var get = async ({ authToken, event }) => {
console.log("ok222");
return {
msg: "Okey Dokey"
};
};
export {
get
};
thdxr
01/18/2022, 6:17 PMRoss Gerbasi
01/18/2022, 6:17 PMthdxr
01/18/2022, 6:18 PM"compilerOptions": {
"module": "esnext",
thdxr
01/18/2022, 6:18 PMRoss Gerbasi
01/18/2022, 6:18 PMRoss Gerbasi
01/18/2022, 6:24 PMvar require_jwt = __commonJS({
"node_modules/jwt-simple/lib/jwt.js"(exports, module) {
var crypto = __require("crypto");
to
var require_jwt = __commonJS({
"node_modules/jwt-simple/lib/jwt.js"(exports, module) {
var crypto = import("crypto");
it does work.. I wonder if there is a way to tell esbuild to do this. Essentially the bundled esbuild output is not module compatible, needs to use import syntax.thdxr
01/18/2022, 6:26 PMRoss Gerbasi
01/18/2022, 6:26 PMRoss Gerbasi
01/18/2022, 6:28 PM// node_modules/jwt-simple/lib/jwt.js
var require_jwt = __commonJS({
async "node_modules/jwt-simple/lib/jwt.js"(exports, module) {
var crypto = await import("crypto");
Ross Gerbasi
01/18/2022, 6:48 PMRoss Gerbasi
01/18/2022, 6:59 PMthdxr
01/18/2022, 7:21 PMRoss Gerbasi
01/18/2022, 7:23 PMrequire
so almost all of them sadlyRoss Gerbasi
01/18/2022, 7:26 PMsrc
folder. How does that work for a deploy? does it deploy a node_modules
or are deploys always bundled?thdxr
01/18/2022, 7:31 PMRoss Gerbasi
01/18/2022, 7:33 PMthdxr
01/18/2022, 7:34 PMRoss Gerbasi
01/18/2022, 8:28 PMMichael Wolfenden
01/20/2022, 12:08 AMaws-sdk@3
export esm modules?