aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

Compiling typescript resolver with esBuild throws `Unexpected token 'export'` on import '@aws-appsync/utils/dynamodb'; #330

Open mattiLeBlanc opened 10 months ago

mattiLeBlanc commented 10 months ago

Hi,

As directed in the docs (https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#migrating-resolvers) I am using the Dynamodb module:

import * as ddb from '@aws-appsync/utils/dynamodb';

but when I build my TS to JS I am getting an error from my esbuild:

export * from './lib/dynamodb-helpers';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .js] (/Users/mattijs/www/respark/apollo/apollo-client-api/node_modules/ts-node/src/index.ts:1608:43)

I am building my ts as follows:

const result = esbuild.buildSync({
    stdin: {
      contents: file,
      loader: 'ts',
    },
    external: ['@aws-appsync/utils'],
    bundle: true,
    write: false,
    platform: 'node',
    target: 'esnext',
    format: 'esm',
    sourcemap: 'inline',
    sourcesContent: false,
  });

I tried adding the '@aws-appsync/utils/dynamodb' to externals but to no avail.

How do I resolve this issue?

mattiLeBlanc commented 7 months ago

Any update on this?