Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbschooley opened this issue Apr 12, 2023 · 2 comments
Labels
pending triage Pending further investigation

Comments

@jbschooley
Copy link

jbschooley commented Apr 12, 2023

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 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 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.

@jbschooley jbschooley changed the title Appsync JS doesn't recognize import aliases Appsync JS doesn't recognize import aliases, breaking resolvers built with esbuild Apr 13, 2023
@onlybakam
Copy link
Contributor

Hey, this is an issue that occurs in the AWS console editor. It shows warnings but you can still save your code. Saving your codes with these imports will work. Can you confirm that is the case?

(we are currently looking at fixing this in the console)

@jbschooley
Copy link
Author

It does look like saving code still works, even with the errors. I just tried pushing my stack with the duplicate imports and it worked, I'm not sure why it wasn't going through a few days ago.

The source map issue is still there, and I wonder if it's related to this. When I try to push code with the source map it saves if there's only one util import, but if there's duplicate util imports it throws that vague error.

@onlybakam onlybakam added the pending triage Pending further investigation label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending triage Pending further investigation
Projects
None yet
Development

No branches or pull requests

2 participants