amazon-textract-response-parser
amazon-textract-response-parser copied to clipboard
JavaScript vs TypeScript issues.
This code works with JavaScript but does not work with TypeScript:
When inspecting my combined.json file I see that it has the expected contents:
TypeScript (run from an AWS Lambda) is throwing this error:
I faced the same issue. Does anyone solved it? :thinking:
Hi both & thanks for raising this,
I've managed to reproduce it when using SAM's (beta) TypeScript Lambda function builder, but am not seeing it when writing TypeScript and just using e.g. tsc
to build it into JS.
I found that changing the Lambda's tsconfig.json
from SAM's default "module": "es2015",
to target "module": "umd"
seemed like it might fix the issue... But not certain yet whether there might be a TRP-side fix we could/should make instead.
Would love to hear:
- Whether this tsconfig fix solves the issue for you? and
- A bit more info about exactly how affected folks are using TypeScript: Is it through SAM as mentioned? Something else? What's in your
tsconfig.json
?)
I solved it with
import { Field, TextractDocument } from 'amazon-textract-response-parser/dist/cjs'
Thanks
After a closer look, I think we should be able to improve this by aligning the standard entry point to CJS instead of UMD (so /dist/cjs
not needed). It'd be consistent with what the AWS SDK for JS itself does, and we can offer modern ES6/esnext bundling as an alternative rather than UMD (also like they do), for any toolchains that want it.
I've rolled it in to the proposed next TRP.js version and done some various usage testing as mentioned in the linked PR.
@dobeerman or others if you have time to try out v0.2.0-alpha.2 from NPM, it'd be great to know whether it works better for you?
Closing as v0.2.0 is now launched already and believe it should fix.