AvaTax-REST-V2-JS-SDK icon indicating copy to clipboard operation
AvaTax-REST-V2-JS-SDK copied to clipboard

Importing into a NodeNext doesn't work as intended. Suggest adding explicit support for ESM.

Open brianreeve opened this issue 8 months ago • 1 comments

Problem

I am upgrading a typescript project to specify module and moduleResolution as "NodeNext", but it breaks our imports and usage of avatax (which follows the README), even with "esModuleInterop": true.

Previously, we specified "module": "ESNext" and "moduleResolution": "bundler" which works but I need to take advantage of NodeNext features.

Example

With NodeNext, this example:

import Avatax from 'avatax';

const Avalara = new Avatax({
  ///...
});

Has an error when instantiating Avatax:

This expression is not constructable.
  Type 'typeof import("/Users/brianreeve/projects/perusall/perusall2/node_modules/avatax/index")' has no construct signatures.ts(2351)

Looking at the last line of lib/AvaTaxClient.js, it's clear that it is a CommonJS export, so the following works:

import Avatax from 'avatax';

const Avalara = new Avatax.default({
  ///...
});

I could live with that, but I also have issues importing AvalaraError from the AvaTaxClient file, which we use in application code error processing:

import { AvalaraError } from 'avatax/lib/AvaTaxClient';

Yields:

Cannot find module 'avatax/lib/AvaTaxClient' or its corresponding type declarations.

Probably because it is not specified as an export on the module.

Proposed Solution

Ideally, this package can offer a modern ESM build target, with the client class, error class, and types explicitly defined as exports.

Alternatively, it might be a quicker/easier path to expose the everything exported by AvaTaxClient directly so we can just do something like:

import Avatax, { AvalaraError } from 'avatax/lib/AvaTaxClient';

Thanks!

brianreeve avatar Mar 28 '25 15:03 brianreeve

@brianreeve Could you try this syntax to see if it works for you?

import { AvalaraError } from 'avatax/lib/AvaTaxClient.js';

svc-developer avatar Apr 11 '25 16:04 svc-developer

Please reopen if you are still having an issue - I was able to get this to work

svc-developer avatar May 28 '25 14:05 svc-developer