amazon-textract-response-parser icon indicating copy to clipboard operation
amazon-textract-response-parser copied to clipboard

JavaScript vs TypeScript issues.

Open ccoddington opened this issue 2 years ago • 4 comments

This code works with JavaScript but does not work with TypeScript:

image

When inspecting my combined.json file I see that it has the expected contents:

image

TypeScript (run from an AWS Lambda) is throwing this error:

image

ccoddington avatar Nov 15 '21 20:11 ccoddington

I faced the same issue. Does anyone solved it? :thinking:

dobeerman avatar Feb 07 '22 21:02 dobeerman

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:

  1. Whether this tsconfig fix solves the issue for you? and
  2. 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?)

athewsey avatar Apr 05 '22 17:04 athewsey

I solved it with

import { Field, TextractDocument } from 'amazon-textract-response-parser/dist/cjs'

dobeerman avatar Apr 05 '22 18:04 dobeerman

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?

athewsey avatar Apr 06 '22 08:04 athewsey

Closing as v0.2.0 is now launched already and believe it should fix.

athewsey avatar May 11 '23 11:05 athewsey