[Fixed] SyntaxError: Unexpected token 'export' in AWS Lambda (Node 14.x) – Javascript

by
Ali Hasan
amazon-web-services aws-lambda node.js

Quick Fix: Change export const handler to module.exports.handler

The Problem:

You are encountering a "SyntaxError: Unexpected token ‘export’" error while running Node.js 14.x in AWS Lambda. You have tried various solutions, including changing the code from "exports" to "module.exports", upgrading the Node.js version, and adding "type": "module" to the package.json, but the error persists.

Q&A

What is the problem in the code?

The code is missing module.exports.handler.

What should I change in the code?

Change export const handler to module.exports.handler.

Video Explanation:

The following video, titled "How to fix Unexpected Token in JSON error (for web developers ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Not a programmer? Read this! ** - If you get this error in an app you didn't make, and/or you're not a web developer... this video will not ...