How to use Sharp in AWS Lambda function? I keep getting errors. (node.js, for image resizing)

I added this Lambda layer to my function, which is described as follows: “This serverless application provides a Lambda Layer that includes the sharp image processing library for Node.js”

I’m now trying to run a Lambda function that uses Sharp, but I keep getting errors.

When I try to run it including an import statement, like so…

import sharp from 'sharp';
...
await sharp(inputImagePath)
    .resize(desiredWidth, desiredHeight)
    .toFile(outputImagePath);

…I get this error message:

{
  "errorType": "Error",
  "errorMessage": "Could not load the "sharp" module using the linux-x64 runtimenPossible solutions:n- Ensure optional dependencies can be installed:n    npm install --include=optional sharpn    yarn add sharp --ignore-enginesn- Ensure your package manager supports multi-platform installation:n    See https://sharp.pixelplumbing.com/install#cross-platformn- Add platform-specific dependencies:n    npm install --os=linux --cpu=x64 sharpn- Consult the installation documentation:n    See https://sharp.pixelplumbing.com/install",
  "trace": [
    "Error: Could not load the "sharp" module using the linux-x64 runtime",
    "Possible solutions:",
    "- Ensure optional dependencies can be installed:",
    "    npm install --include=optional sharp",
    "    yarn add sharp --ignore-engines",
    "- Ensure your package manager supports multi-platform installation:",
    "    See https://sharp.pixelplumbing.com/install#cross-platform",
    "- Add platform-specific dependencies:",
    "    npm install --os=linux --cpu=x64 sharp",
    "- Consult the installation documentation:",
    "    See https://sharp.pixelplumbing.com/install",
    "    at Object.<anonymous> (/opt/nodejs/node_modules/sharp/lib/sharp.js:114:9)",
    "    at Module._compile (node:internal/modules/cjs/loader:1469:14)",
    "    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)",
    "    at Module.load (node:internal/modules/cjs/loader:1288:32)",
    "    at Module._load (node:internal/modules/cjs/loader:1104:12)",
    "    at Module.require (node:internal/modules/cjs/loader:1311:19)",
    "    at require (node:internal/modules/helpers:179:18)",
    "    at Object.<anonymous> (/opt/nodejs/node_modules/sharp/lib/constructor.js:10:1)",
    "    at Module._compile (node:internal/modules/cjs/loader:1469:14)",
    "    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)"
  ]
}

Then when I try to run Sharp commands without any overt import statement, it gives me “sharp is undefined” errors.

I’m just very confused because my understanding is, the Lambda layer makes it so I can use Sharp in my Lambda function? What am I missing or doing wrong here? Thanks.