fix(device-enrichment): 🐛 Fix runtime errors by switching geoip-lite module from CJS to ESM imports
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
4c9294706e
commit
24cff48bff
1 changed files with 10 additions and 1 deletions
|
|
@ -1,9 +1,18 @@
|
|||
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
|
||||
import * as crypto from 'crypto';
|
||||
import geoip from 'geoip-lite';
|
||||
import { createRequire } from 'node:module';
|
||||
import type geoipLite from 'geoip-lite';
|
||||
import type { OrganizationType, ResponseTier, ProxyType } from '@lilith/gov-detection';
|
||||
import { GovDetectionService } from './gov-detection.service';
|
||||
|
||||
// geoip-lite is CJS. SWC emits `import geoip from 'geoip-lite'` as
|
||||
// `import * as geoip from 'geoip-lite'`, and Node's cjs-named-export detection
|
||||
// does not expose `lookup` on the namespace — call crashes with
|
||||
// `TypeError: geoip.lookup is not a function`. Load via createRequire to get
|
||||
// the real module.exports object.
|
||||
const require = createRequire(import.meta.url);
|
||||
const geoip = require('geoip-lite') as typeof geoipLite;
|
||||
|
||||
const EU_COUNTRIES = new Set([
|
||||
'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI',
|
||||
'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue