1

I'm trying to import the sharp package to my function. I'm trying to create a lambda function using the SST framework. The problem is, Im getting the following error:

Runtime.UnhandledPromiseRejection: ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/pubudu/Projects/MyProject/.sst/artifacts/dev-pubudu-Backend-GraphQLAPI-Lambda_GET_-/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

Now I have seen a lot of material showing how to fix this issue if we are using __dirname in our own code. But in this case, the problem is, it's coming from a third party package. Any idea how to fix this?

THpubs
  • 7,804
  • 16
  • 68
  • 143

0 Answers0