hey all, Iโ€™m curious what the state of v1 construc...
# help
j
hey all, Iโ€™m curious what the state of v1 constructs are? Seems like the docs for them bleed some of the v0 construct information? Mostly switching between a Class vs Function declaration for each.
Copy code
import { Function, StackContext } from '@serverless-stack/resources';

export function MyStack({ stack }: StackContext) {
  new Function(stack, 'Func', {
    srcPath: 'backend',
    handler: 'services/sample/index.handler',
  });
}
gives a type error:
TS2345: Argument of type 'Stack' is not assignable to parameter of type 'Construct'.
related to the docs, I had all the class based stuff working with v0 constructs but decided to start playing with v1 stuff today.
t
you're saying that above snippet gives you a type error?
and you see that snippet in a v0 construct doc?
f
@Jarod Stewart I just gave ur snippet a try, it seems to work, and I donโ€™t get the TypeError.
Can you share the SST version in ur
package.json
and what your index file looks like?
j
Ah good thoughts. I will look into those and post later ๐Ÿ˜… The above snippet did give me the type error... Likely some yarn lock not clearing to using the beta version.
my index.ts for creating the App looks like this:
Copy code
import { App } from '@serverless-stack/resources';

import { GoodUncle, MyStack } from './MyStack';

export default function main(app: App): void {
  app.setDefaultFunctionProps({
    runtime: 'nodejs14.x',
  });

  app.stack(MyStack).stack(GoodUncle);
}
Copy code
"@serverless-stack/cli": "1.0.0-beta.21",
"@serverless-stack/resources": "1.0.0-beta.21",
"@serverless-stack/static-site-env": "1.0.0-beta.21",
t
Still seeing the type error?
j
I do >.<
t
Can you try wiping node modules if you haven't?
j
i did
rm -rf node_modules
in my root and frontend package
t
Can you also show us your MyStack file
that's where the error is right
j
myStack.ts
Copy code
import { Function, NextjsSite, StackContext, Table } from '@serverless-stack/resources';

export function MyStack({ stack }: StackContext) {
  new Function(stack, 'Func', {
    bundle: {
      esbuildConfig: {
        plugins: 'config/esbuild.js',
      },
    },
    srcPath: 'backend',
    handler: 'services/sample/index.handler',
  });
}

export function GoodUncle({ stack }: StackContext) {
  // Create the table
  const subscriptionsTable = new Table(stack, 'Subscriptions', {
    fields: {
      email: 'string',
      date: 'string',
    },
    primaryIndex: { partitionKey: 'email', sortKey: 'date' },
  });

  // Create a Next.js site
  const site = new NextjsSite(stack, 'Site', {
    path: 'gooduncle',
    environment: {
      // Pass the table details to our app
      REGION: stack.region,
      SUBSCRIPTION_TABLE_NAME: subscriptionsTable.tableName,
    },
  });

  // Allow the Next.js API to access the table
  site.attachPermissions([subscriptionsTable]);

  // Show the site URL in the output
  stack.addOutputs({
    URL: site.url,
  });

  return {
    subscriptionsTable,
    site,
  };
}
t
And what line is the type error on?
j
i get it on any
new <Construct>
(Function, Table, NextjsSite) on the first parameter
(stack,
t
hm that's really odd
j
yaeh >.<
t
What's your aws-cdk-lib version?
j
"aws-cdk-lib": "2.20.0"
t
let me double check if I can recreate
yeah no type error ๐Ÿ˜…
j
heh, no worries. Thank you for your time! ๐Ÿ˜„
I will keep banging my head on this one and maybe reboot the repo haha
t
one more thing do you get the error if you run
tsc --noEmit
j
yup
t
incredible ๐Ÿ˜ฎ
the only thing I can imagine is somehow there's a node_modules thing going on - no idea what else could be it
j
yeah
using yarn and first time with workspaces in this repo
oooh
t
sorry I realized the latest version of that wasn't published haha
j
ah
ohhh, may have fixed something running
yarn install --force
lol
t
hooray
j
๐Ÿคฆโ€โ™‚๏ธ
wow, thanks again for the help!