'Msg: ERROR Error: Uncaught (in promise): ReferenceError: __dirname is not defined

I have a Angular Application and recently added this package: https://www.npmjs.com/package/geo-tz

I created a new class test.ts

import {find} from "geo-tz";

export class Test {


  public getTimezone() {

    console.log(find(47.650499, -122.350070));
  }
}


this is called from a page like the following:

    const blah = new Test();
    blah.getTimezone();

however when I try to open the page I get the following error in the console:

E/Capacitor/Console: File: http://localhost/vendor.js - Line 2288 - Msg: ERROR Error: Uncaught (in promise): ReferenceError: __dirname is not defined ReferenceError: __dirname is not defined



Solution 1:[1]

The package you're trying to use is a Node-based one.

Angular is browser-based.

You cannot use Node-based packages into browser-based applications.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 temp_user