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

Jett Robin Andres

11/24/2021, 11:59 PM
Hi everyone, I’m using a nodejs library to verify my Cognito JWT token being passed from the client after a successful login. I’m getting the ff error whenever I try to import the library into my lambda (see first image). Upon inspecting the library, it says in its README that it can be used in NodeJS 14 and above. I noticed that in my entry file
stacks/index.ts
the set default function runtime for nodeJs is just
nodeJs12.x
, is this the one causing the error? Other stackoverflow answers and github comments recommend updating my
@types/node
dependency but that still didn’t do the trick. I checked my SST version and it’s (a bit?) outdated since I started.
Copy code
SST: 0.45.0
CDK: 1.125.0
In SST v0.46.0’s changelog, there was a PR related to removal of the said node crypto package. Will updating to
v0.46.0
most likely solve my case? How do we go about updating SST? Would you guys recommend me to jump immediately to
v0.53.0
or just go about it incrementally? I’m missing out on all the good stuff too so I figured maybe it’s about time while my SST app’s still young
ö

Ömer Toraman

11/25/2021, 10:36 AM
Can you log the
KeyObject
and see if it is
undefined
or not?
I guess it would be better to start with a new SST project. For the latest version, the default runtime is node14, and the @types/node is at v14.X.X However, I’m not sure if that solves the problem. The thing is that SST is making a type check and it fails. By the way you can disable the type checking using
sst.json
and setting
typeCheck
to
false
, so it will not error our
Seems like you cannot use it even if u upgrade the SST:
That’s from Node documentation
It is added in node v15, so it is not available in v14 or v12
j

Jett Robin Andres

11/25/2021, 10:42 AM
so it’s more of a library issue then @Ömer Toraman?
ö

Ömer Toraman

11/25/2021, 10:43 AM
Yep. The class is available for node version 15 and beyond, but the available lambda runtimes are v12, and v14. So CryptoKey is not available
You should see undefined when you log
CryptoKey
It’s not a library issue, it is a node version issue
NodeJS added that class starting from v14
v15*
j

Jett Robin Andres

11/25/2021, 10:44 AM
I see. I guess I’ll look for other lib alternatives. Thanks @Ömer Toraman!
ö

Ömer Toraman

11/25/2021, 10:46 AM
However, why do u use CryptoKey if u r using that library?
I mean since that library exists, it should be compatible with the lambda runtimes. It is specifically written for lambda
or not 🤔
j

Jett Robin Andres

11/25/2021, 10:47 AM
I think it’s a dependency from the library
I haven’t added any code yet other than the import code
Copy code
import { CognitoJwtVerifier } from "aws-jwt-verify"
I was able to make it work and decode my JWT via hot-reload by running
npx sst start
first and then adding my import code and saving after
ö

Ömer Toraman

11/25/2021, 10:49 AM
Wait I might be mistaking
Oh no it is added to v14 as well
remove it
Remove the node type
Copy code
yarn remove @types/node
Add this:
Copy code
yarn add -D @types/node@"<15.0.0"
But better to create a new SST app with the latest version (it is already v14 with the appropriate @types/node)
j

Jett Robin Andres

11/25/2021, 10:52 AM
got this! thanks @Ömer Toraman. I think the upgrade path is more future-proof
ö

Ömer Toraman

11/25/2021, 10:52 AM
i agree
f

Frank

11/25/2021, 7:56 PM
Thanks @Ömer Toraman!
@Jett Robin Andres were you able to update to 0.53.0?
j

Jett Robin Andres

11/26/2021, 12:07 PM
@Frank soooo my sst update was successful. I even updated my nodejs default runtime to
nodejs14.x
(see first screenshot) and I’m glad to see that my lambdas were still working properly. phew. I installed
@types/node
as suggested by @Ömer Toraman via
Copy code
npm i @types/node@"<15.0.0"
buuut the problem still persisted though haha. I have yet to try the library on a fresh SST project!
UPDATE: I installed
@types/node@"^16.11.10'
and the error’s finally gone!
ö

Ömer Toraman

11/26/2021, 2:54 PM
lol
3 Views