Interesting article, although the statement that "AppSync uses the latest ES module version" is simply untrue and can lead to issues when working on something more than hello world. AWS docs clearly say that APPSYNC_JS supports only a subset of ES 6 functionality, and ES 6 = ES2015, after 2015 we had 17, 18, 19, 20, 21, 22, 23 & 24, so it's doesn't even come close to ESNEXT, which basically means "take latest".
Unless we get real implementation of APPSYNC_JS target for ESBuild we can only try to make things work. My suggestion would be to:
Unfortunately it's not a seamless experience as you can still stumble upon functionality that will transpile to something that can't work, but you would at least get clear error during build step when it happens.
Thank you for the tutorial, really amazing. I am getting __filename is not defined error on deploy. Any thoughts?
Thanks for the tutorial I just tried this out in my CDK Typescript project and it deploys fine, but when I try calling the endpoint Appsync throws "Unable to transform the template"
import esbuild from 'esbuild';
export function bundleResolver(entryPoint: string): string { const result = esbuild.buildSync({ entryPoints: [entryPoint], bundle: true, write: false, platform: 'node', target: 'esnext', format: 'esm', sourcemap: 'inline', sourcesContent: false, });
if (result?.outputFiles && result?.outputFiles?.length > 0 && result?.outputFiles[0]?.text) { return result.outputFiles[0].text; } else { throw new Error('Bundling failed: No output files generated'); } }
sarahlison
always listen
Is there no way to completely fix the problem? I don't want such troubles to happen while the process is being done.