awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
594 stars 43 forks source link

[BUG] Unexpected Token '.' on EC2 instance running NodeJS 14, 16, and 18 #149

Closed ttran13 closed 7 months ago

ttran13 commented 8 months ago

Describe the bug Hi, I am still getting the Unexpected token '.' error that was found with using NodeJS 12 and below. I upgraded from 13 to 14 hoping this would solve the issue, but the issue still persists and I cannot run my app on the EC2 instance.

Versions Which version of aws-jwt-verify are you using? 4.0.0 Are you using the library in Node.js or in the Web browser? In Node.js If Node.js, which version of Node.js are you using? (Should be at least 14) I tried it on 14, 16, and 18 If Web browser, which web browser and which version of it are you using? If using TypeScript, which version of TypeScript are you using? (Should be at least 4) Using JavaScript

To Reproduce My app only uses aws-jwt-verify to verify the token from Cognito. It is deployed on an EC2 instance running Amazon Linux. I am able to run the app locally, but on the server, it gets the error. This is the stack trace.

Started LTPS NodeJS Test Application. /var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:322 return new this(verifyProperties, additionalProperties?.jwksCache); ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:1039:16) at Module._compile (internal/modules/cjs/loader.js:1087:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:972:32) at Function.Module._load (internal/modules/cjs/loader.js:872:14) at Module.require (internal/modules/cjs/loader.js:1012:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (/var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/index at Module._compile (internal/modules/cjs/loader.js:1123:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) server.service: main process exited, code=exited, status=1/FAILURE Unit server.service entered failed state. server.service failed. server.service holdoff time over, scheduling restart. Stopped LTPS NodeJS Test Application. Started LTPS NodeJS Test Application. /var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:322 return new this(verifyProperties, additionalProperties?.jwksCache); ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:1039:16) at Module._compile (internal/modules/cjs/loader.js:1087:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:972:32) at Function.Module._load (internal/modules/cjs/loader.js:872:14) at Module.require (internal/modules/cjs/loader.js:1012:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (/var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/index at Module._compile (internal/modules/cjs/loader.js:1123:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) server.service: main process exited, code=exited, status=1/FAILURE Unit server.service entered failed state. server.service failed. server.service holdoff time over, scheduling restart. Stopped LTPS NodeJS Test Application. Started LTPS NodeJS Test Application. /var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:322 return new this(verifyProperties, additionalProperties?.jwksCache); ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:1039:16) at Module._compile (internal/modules/cjs/loader.js:1087:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:972:32) at Function.Module._load (internal/modules/cjs/loader.js:872:14) at Module.require (internal/modules/cjs/loader.js:1012:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (/var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/index at Module._compile (internal/modules/cjs/loader.js:1123:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) server.service: main process exited, code=exited, status=1/FAILURE Unit server.service entered failed state. server.service failed. server.service holdoff time over, scheduling restart. Stopped LTPS NodeJS Test Application. Started LTPS NodeJS Test Application. /var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:322 return new this(verifyProperties, additionalProperties?.jwksCache); ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:1039:16) at Module._compile (internal/modules/cjs/loader.js:1087:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:972:32) at Function.Module._load (internal/modules/cjs/loader.js:872:14) at Module.require (internal/modules/cjs/loader.js:1012:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (/var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/index at Module._compile (internal/modules/cjs/loader.js:1123:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) server.service: main process exited, code=exited, status=1/FAILURE Unit server.service entered failed state. server.service failed. server.service holdoff time over, scheduling restart. Stopped LTPS NodeJS Test Application. Started LTPS NodeJS Test Application. /var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:322 return new this(verifyProperties, additionalProperties?.jwksCache); ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:1039:16) at Module._compile (internal/modules/cjs/loader.js:1087:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:972:32) at Function.Module._load (internal/modules/cjs/loader.js:872:14) at Module.require (internal/modules/cjs/loader.js:1012:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (/var/www/nodejs-script/express-test/node_modules/aws-jwt-verify/dist/cjs/index at Module._compile (internal/modules/cjs/loader.js:1123:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) server.service: main process exited, code=exited, status=1/FAILURE Unit server.service entered failed state. server.service failed. server.service holdoff time over, scheduling restart. Stopped LTPS NodeJS Test Application. start request repeated too quickly for server.service Failed to start LTPS NodeJS Test Application. Unit server.service entered failed state. server.service failed.

hakanson commented 8 months ago

I am able to run the app locally, but on the server, it gets the error.

This seems to imply the code works, but your EC2 runtime (node version, or config) is different than local. Can you node --version and npm --version for each environment?

ttran13 commented 7 months ago

I just checked the node version on the EC2 instance and it was 13.12.0 which is weird since I manually updated it myself. I think since it is managed through my organization's IT department, they are the only ones allowed change the verision, so I will go that route.

hakanson commented 7 months ago

Thanks for the update. I'll close this issue since error is from an unsupported version.