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

tables + typescript do not build/compile #1481

Open
Xiphe opened this issue Apr 22, 2024 · 2 comments
Open

tables + typescript do not build/compile #1481

Xiphe opened this issue Apr 22, 2024 · 2 comments

Comments

@Xiphe
Copy link

Xiphe commented Apr 22, 2024

Describe the issue

When I setup a fresh arc project
And I add a table
And I install the typescript plugin
And I run arc sandbox

Then I expect the dev-sandbox to start
But instead I get a bunch of errors

✘ [ERROR] Could not resolve "@aws-sdk/client-dynamodb"
    node_modules/@architect/functions/src/tables/legacy.js:16:25:
      16 │     let dynamo = require('@aws-sdk/client-dynamodb')

Steps to reproduce

With reproduce repo

https://github.com/Xiphe/architect-tables-typescript-issue

git clone [email protected]:Xiphe/architect-tables-typescript-issue.git
cd architect-tables-typescript-issue
npm i 
npm start

OR from scratch

  1. run npm init @architect your-app and cd into your-app
  2. run npm install @architect/functions @architect/plugin-typescript @types/node
  3. change your app.arc to this
    @app
    test-arc
    
    @http
    get /
    
    @aws
    # profile default
    region us-west-2
    architecture arm64
    runtime typescript
    
    @plugins
    architect/plugin-typescript
    
    @tables
    people
      pplID *String
    
  4. rename src/http/get-index/index.mjs to ./index.ts
  5. change the contents of that file to
    import { Context, APIGatewayProxyResult, APIGatewayEvent } from "aws-lambda";
    import arc from "@architect/functions";
    console.log(arc);
    
    // learn more about HTTP functions here: https://arc.codes/http
    export async function handler(
      event: APIGatewayEvent,
      context: Context,
    ): Promise<APIGatewayProxyResult> {
    // REST AS IS...
  6. run npm start, arc sandbox or arc deploy
  7. See errors in console
    Compiling TypeScript
    ✘ [ERROR] Could not resolve "@aws-sdk/client-dynamodb"
    
        node_modules/@architect/functions/src/tables/legacy.js:16:25:
          16 │     let dynamo = require('@aws-sdk/client-dynamodb')
             ╵                          ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
      You can mark the path "@aws-sdk/client-dynamodb" as external to exclude it from
      the bundle, which will remove this error and leave the unresolved path in the
      bundle. You can also surround this "require" call with a try/catch block to handle
      this failure at run-time instead of bundle-time.
    

Expected behavior

I would expect the dev environment to start

Also since 11.x I would expect that I don't need to install the old aws client

Screenshots

image

Desktop

  • OS: MacOS 13.4
  • Node: 20.11
@Xiphe
Copy link
Author

Xiphe commented Apr 22, 2024

What seems to work is:

  1. Add this to the app.arc
    @typescript
    esbuild-config custom-build.cjs
    
  2. add this custom-build.cjs file
    /** @type {import('esbuild').BuildOptions} */
    module.exports = {
      external: [
        "@aws-sdk/client-dynamodb",
        "@aws-sdk/lib-dynamodb",
        "aws-sdk/clients/dynamodb",
        "@smithy/node-http-handler", // not sure about this one, seems to be required sometimes
      ],
    };

@ryanblock
Copy link
Member

@Xiphe thanks for spelunking that, it sounds like we need to update the documentation to include those directions on keeping those deps as external.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants