taxjar / taxjar-node

Sales Tax API Client for Node
https://developers.taxjar.com/api/reference/?javascript
MIT License
53 stars 24 forks source link

Cannot import Taxjar using TypeScript #13

Closed zgosalvez closed 6 years ago

zgosalvez commented 6 years ago

This used to work on v1, now it throws an error on v2.

import * as taxjar from 'taxjar';
Module '"/node_modules/taxjar/dist/taxjar"' resolves to a non-module entity and cannot be imported using this construct.

Attempting to import as documented throws a different error.

import Taxjar from 'taxjar';
Module '"/node_modules/taxjar/dist/taxjar"' has no default export.

Here's my tsconfig.json file.

{
  "compilerOptions": {
    "lib": ["es2017"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "strictNullChecks": true
}
fastdivision commented 6 years ago

@zgosalvez This looks like an ES6 / CommonJS interop issue since we're now using TypeScript on our end to compile the package. Can you pass esModuleInterop in your tsconfig.json?

{
  "compilerOptions": {
    "lib": ["es2017"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6",
    "esModuleInterop": true
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "strictNullChecks": true
}

Afterwards, go ahead and use:

import Taxjar from 'taxjar';
fastdivision commented 6 years ago

Updated the README authentication example to address this issue.

zgosalvez commented 6 years ago

Thanks, @fastdivision . That did it, tho I had to modify how I imported other dependencies.

eboswort commented 5 years ago

Is there a fix for this that doesn't require esModuleInterop? That creates a bunch of other issues in the app I'm working on.

eboswort commented 5 years ago

Hmm I guess it wasn't actually that hard to fix those other issues. So nevermind :)

brannondorsey commented 3 years ago

Is there a fix for this that doesn't require esModuleInterop? That creates a bunch of other issues in the app I'm working on.

We'd like to use this module, however we aren't in a position to refactor the rest of our imports to use the esModuleInterop compiler flag. Is there another way to use this module?