Error when using JSDom library in functions


I have a function that uses JSDom library to process an HTML.
The function has .mjs extension and when building it, raises the following warning:

▲ [WARNING] "./xhr-sync-worker.js" should be marked as external for use with "require.resolve"

      31 │ const syncWorkerFile = require.resolve ? require.resolve("./xhr-sync-worker.js") : null;
         ╵                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I tried to solve this problem by patching the JSDom library (based on suggestions from: Problem bundling simple jsdom example - request.resolve · Issue #1311 · evanw/esbuild · GitHub)
I changed the following line:
const syncWorkerFile = require.resolve ? require.resolve(“./xhr-sync-worker.js”) : null;
const syncWorkerFile = require.resolve(‘jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js’);
Locally, when using netlify dev, the function works properly, without any errors.
But, when I deploy my application, the function calls throws the error:

ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError",
"errorMessage":"Error: Cannot find module 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
\nRequire stack:
\n- /var/task/netlify2/functions/importFromUrl/index.js
\n- /var/task/importFromUrl.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'",
"Require stack:","- /var/task/netlify2/functions/importFromUrl/index.js","- /var/task/importFromUrl.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," 
at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," 
at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}

Details about my environment:
Locally: node 20.10.0
Node configured in Netlify: 20.10.0
Netlify build configuration

  command = "react-scripts"  
  functions = "netlify2/functions"  
  publish = "build"  
    from = "/*"  
    to = "/index.html"  
    status = 200  
  command = "npm start" # Command to start your dev server  
  port = 3001 # Port that the dev server will be listening on  

  node_bundler = "esbuild"  
  ignored_node_modules = ["ky-universal"]

Do you have any thoughts on how could I fix this problem?
Thank you very much

The following change:

should fix it.

It works! Thank you very much for your help!