aws / aws/aws-appsync-community

Appsync JS doesn't recognize import aliases, breaking resolvers built with esbuild

Open
#285 2 comments 1 reaction 0 assignees View on GitHub
pending triage
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

If I import `utils` with an alias, the editor throws 3 errors:
```
Expected 'from' and instead saw '}'.
Expected '(string)' and instead saw 'from'.
Missing ";" before statement
```

This may seem like a bit of a useless thing to fix, because why would you use anything other than `import {util} from "@aws-appsync/utils"` to import utils?

Well, I'm following [these directions](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#additional-utilities) to compile my resolvers with esbuild. When my main resolver file imports utils and imports another custom module that also imports utils, esbuild will insert duplicate import statements, one for each file that imports it:
```
import { util as util3 } from "@aws-appsync/utils";
import { util } from "@aws-appsync/utils";
import { util as util2 } from "@aws-appsync/utils";
```

It appears that this has been a [known issue](https://github.com/evanw/esbuild/issues/475) in esbuild for years and has not yet been fixed, and it doesn't seem like there's a way around it, so it would be great if AppSync could handle it appropriately.

edit: this also *might* be breaking source maps. I modified my build process to keep the first util import and remove the rest, but received an error (with no other details) when saving the code. Removing the source map fixed that. I can't tell if this is due to issues parsing the source map because the sources it's referring to are gone or simply because the source map was too long.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the resolver import case described in the issue, using the linked AppSync resolver documentation and an esbuild-built resolver with duplicate utility imports. Check the editor errors and the separate source-map behavior; done means aliased and repeated imports parse and save successfully without the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
api, cloud
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.