Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validateVat import is meant to be used as a function but is an Object #46

Open
front-depiction opened this issue Jan 14, 2024 · 0 comments

Comments

@front-depiction
Copy link

In the docs validateVat is used as a function

// taken from "/readme.md"
import validateVat, {ViesValidationResponse} from 'validate-vat-ts';

const consumer = async () => {
  try {
    const validationInfo: ViesValidationResponse = await validateVat(CountryCodes.Germany, "12323");
  } catch (e) {
    console.log(e);
  }
}

Running the block of code leads to

TypeError: __vite_ssr_import_5__.default is not a function

Some logging shows that validateVat import is an Object and not a function.

import validateVat from 'validate-vat-ts';
console.log(validateVat);

output:

{
  ViesServerError: [Function: ViesServerError],
  ViesClientError: [Function: ViesClientError],
  VAT_SERVICE_URL: 'https://ec.europa.eu/taxation_customs/vies/services/checkVatService',
  VAT_TEST_SERVICE_URL: 'https://ec.europa.eu/taxation_customs/vies/services/checkVatTestService',
  CountryCodes: {
    Austria: 'AT',
    Belgium: 'BE',
    Bulgaria: 'BG',
    Croatia: 'HR',
    Cyprus: 'CY',
    CzechRepublic: 'CZ',
    Denmark: 'DK',
    Estonia: 'EE',
    Finland: 'FI',
    France: 'FR',
    Germany: 'DE',
    Greece: 'EL',
    Hungary: 'HU',
    Ireland: 'IE',
    Italy: 'IT',
    Latvia: 'LV',
    Lithuania: 'LT',
    Luxembourg: 'LU',
    Malta: 'MT',
    Netherlands: 'NL',
    Poland: 'PL',
    Portugal: 'PT',
    Romania: 'RO',
    Slovakia: 'SK',
    Slovenia: 'SI',
    Spain: 'ES',
    Sweden: 'SE',
    NorthernIreland: 'XI'
  },
  default: [Function: validateVat]
}

to actually use the function as intended, extract the default function from said object

import validateVat, { type ViesValidationResponse } from 'validate-vat-ts';
const validateVatFn: (
	countryCode: CountryCodes,
	vatNumber: string,
	serviceUrl?: string
) => Promise<ViesValidationResponse> = (validateVat as any).default;
console.log(validateVatFn);

output

[Function: validateVat]

VITE v5.0.11
NODE v21.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant