I'm trying to use jsdom in an AWS Lambda function, bundled with serverless-esbuild. However, I'm encountering the following error:
[WARNING] "./xhr-sync-worker.js" should be marked as external for use with "require.resolve" [require-resolve-not-external]
node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:31:57:
31 │ const syncWorkerFile = require.resolve ? require.resolve("./xhr-sync-worker.js") : null;
╵ ~~~~~~~~~~~~~~~~~~~~~~
✖ Error: Cannot find module './xhr-sync-worker.js'
Require stack:
Here is my yml file:
service: service-name
custom:
esbuild:
bundle: true
minify: false
sourcemap: true
target: 'node20'
external:
- './xhr-sync-worker.js'
platform: 'node'
concurrency: 10
provider:
name: aws
runtime: nodejs20.x
plugins:
- serverless-esbuild
- serverless-offline
functions:
getDailyPrices:
handler: src/functions/getDailyPrices/handler.function
I've tried marking xhr-sync-worker.js as an external module, but the issue persists. How can I resolve this error and properly bundle jsdom for use in AWS Lambda with serverless-esbuild?