aws / aws/aws-appsync-community

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

Open
#330 1 comment 0 reactions 0 assignees View on GitHub
pending triage
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Research direction

Start with the reported esbuild.buildSync configuration and the import of @aws-appsync/utils/dynamodb, then reproduce the Unexpected token 'export' error using the command setup described in the issue. Done means the TypeScript resolver compiles successfully without that syntax error while retaining the documented DynamoDB import.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.