Closed JoshWalshaw closed 2 years ago
Hey @JoshWalshaw -- I don't know what your setup is (looks like nestjs), but we use this library with typescript all the time.
See it working here as well: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAYQDbAKYDt4DMoRHAciwAtgoBaAa2BnIGMUMYCBuAWAChO6J0BneAzSY4AXjjpUAd0SNMACgDeAIwCGfVAFUoSAFyFiMGGF0B6U6rohUAOh4hTJMgQC+ASnZcOQA
Can you push up a git repo reproducing your problem?
Hey @bkaney, thanks for the quick response!
I've created a super quick repo which can be found here. All you'd need to do is run yarn start:dev
after installing dependencies and you should see the error in the terminal.
For reference, I've also put down the output of my console below too, but it's the same error I'm getting in the actual project I'm trying to implement - only that in the repo linked above I'm throwing it in the bootstrap method so that it attempts to do things on startup as opposed to when hitting an endpoint.
Hopefully this helps, let me know if there's anything else you'd want to know!
[14:19:58] Starting compilation in watch mode...
[14:20:01] Found 0 errors. Watching for file changes.
/Users/joshwalshaw/Documents/Node/fhir/src/main.ts:7
const client = new Client({ baseUrl: 'http://foo.com' });
^
TypeError: fhir_kit_client_1.default is not a constructor
at bootstrap (/Users/joshwalshaw/Documents/Node/fhir/src/main.ts:7:18)
at Object.<anonymous> (/Users/joshwalshaw/Documents/Node/fhir/src/main.ts:13:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Hi @JoshWalshaw - You need to turn on https://www.typescriptlang.org/tsconfig#esModuleInterop in your tsconfig.json. Once enabled, everything is fine.
Right now, the library is intentionally plain vanilla JS (requiring this setting)
Amazing! I added that into my tsconfig.json
and it's working fine now, thanks a bunch for this - much appreciated.
Might be worth adding something in the ReadMe if this is a requirement so similar issues in the future don't get created, If you'd like I can fork and make a PR with something in?
Expected Behavior
Should be able to create a new instance of
Client
when using ES6 imports when following the documentation to implement the library.Actual Behavior
Getting the following error when using
import Client from 'fhir-kit-client';
.You can however get access to an object when doing
const Client = require('fhir-kit-client');
however this doesn't provide any typescript support this way.Steps to Reproduce the Problem
Simplest form would be:
yarn add fhir-kit-client
Specifications
^1.9.1