title: NodeJS with ESM: internal/process/promises:246 | triggerUncaughtException(err, true /* fromPromise */) | finalizer.unsubscribe is not a function
body: <p>I am creating an <strong>observable</strong> (RxJS) in <strong>NodeJS</strong> using <strong>ESM</strong>.
  Inside the <strong>observable</strong> I am performing a query with <strong>mongoose</strong>.
  I get the result, but the console returns errors (detailed at the end of the question).</p>
  <p>I have tried to perform the operation with Javascript <strong>promises</strong> and <strong>without promises</strong> trying to handle the errors with the operators (<strong>try catch</strong>).</p>
  <pre><code>//-----------------------------------------------------------------//
  // WITHOUT PROMISES:
  //-----------------------------------------------------------------//
  // Create observable obsAuth:
  const obsAuth = new Observable(async (observer) =&gt; {
    try{
      const doc = await people.Model.findOne();
      observer.next(doc);
    } catch (err) {
        observer.error(err);
    }
  
    // Finish observer:
    observer.complete();
  });
  
  // Observe sub-element content (Subscribe):
  let subAuth = obsAuth.subscribe({
    next: doc =&gt; {
      res.status(200).send({ success: true, people_data: doc });
      console.log(doc);
    },
    error: err =&gt; {
      res.status(500).send({ success: false, error: err });
      console.error('Error: ' + err);
    },
    complete: () =&gt; console.log('Suscripción finalizada')
  });
  
  // Unsuscribe:
  subAuth.unsubscribe();
  //-----------------------------------------------------------------//
  
  
  //-----------------------------------------------------------------//
  // WITH PROMISES:
  //-----------------------------------------------------------------//
  // Build people query:
  const peopleQueryMongoDB = people.Model.findOne();
  
  // Create observable obsAuth:
  const obsAuth = new Observable(async (observer) =&gt; {
    // Excecute people query (Promise):
    await peopleQueryMongoDB.exec()
    .then((doc) =&gt; {
      observer.next(doc);
    })
    .catch((err) =&gt; {
      observer.error(err);
    });
  
    // Finish observer:
    observer.complete();
  });
  
  // Observe sub-element content (Subscribe):
  let subAuth = obsAuth.subscribe({
    next: doc =&gt; {
      res.status(200).send({ success: true, people_data: doc });
      console.log(doc);
    },
    error: err =&gt; {
      res.status(500).send({ success: false, error: err });
      console.error('Error: ' + err);
    },
    complete: () =&gt; console.log('Suscripción finalizada')
  });
  
  // Unsuscribe:
  subAuth.unsubscribe();
  //-----------------------------------------------------------------//
  </code></pre>
  <p>In both cases I have exactly the same behavior.
  I get the results and with the following error in the console.</p>
  <p><strong>CONSOLE ERRORS:</strong></p>
  <pre><code>node:internal/process/promises:246
            triggerUncaughtException(err, true /* fromPromise */);
            ^
  Error
  ...
  ...
  at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    message: '1 errors occurred during unsubscription:\n' +
      '1) TypeError: finalizer.unsubscribe is not a function',
    errors: [
      TypeError: finalizer.unsubscribe is not a function
  ...
  ...
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
    ]
  }
  </code></pre>
  <p>Thanks a lot in advance!!</p>