Title
m

Mischa Spiegelmock

01/20/2022, 6:22 PM
I discovered this esbuild option today - https://esbuild.github.io/api/#main-fields lets you tell esbuild to actually import the ESM version of dependencies because it doesn’t do that even if you do format=esm, it will select the CJS version
t

thdxr

01/20/2022, 6:23 PM
wtf
good find we'll turn those on
r

Ross Gerbasi

01/20/2022, 6:57 PM
well what the heck... 🤦‍♂️
m

Mischa Spiegelmock

01/20/2022, 8:14 PM
it’s pretty hard to build and test aws-cdk…
especially with SST because SST yells at me for not having 2.7.0 if i’m linking my locally-built version
Mismatched versions of AWS CDK packages. Serverless Stack currently supports 2.7.0. Fix using:

  npm install aws-cdk-lib@2.7.0 --save-dev --save-exact

Learn more about it here — <https://docs.serverless-stack.com/known-issues>


Error: invalid ConstructNode type
    at Function._unwrap (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/core/lib/construct-compat.ts:146:13)
    at new Construct (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/core/lib/construct-compat.ts:64:31)
    at new Resource (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/core/lib/resource.ts:71:5)
    at new LayerVersionBase (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/layers.ts:48:1)
    at new Import (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/layers.ts:101:5)
    at Function.fromLayerVersionAttributes (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/layers.ts:106:12)
    at Function.fromLayerVersionArn (/Users/cyber/dev/aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/layers.ts:89:25)
    at getSentryLayerByLang (/Users/cyber/dev/platform/packages/infra/lib/constructs/sentryLambdaLayer/sentryLambdaLayer.ts:39:30)
    at TomboStack.configureLambdaDefaults (/Users/cyber/dev/platform/packages/infra/stacks/tombo.ts:147:16)
    at new TomboStack (/Users/cyber/dev/platform/packages/infra/stacks/tombo.ts:51:10)
I’m not sure how I can test my changes
t

thdxr

01/20/2022, 8:21 PM
@Frank struggled with this as well but I think he got something working
I'm going to push an update for sst's function to add these main fields
m

Mischa Spiegelmock

01/20/2022, 8:21 PM
ok. i’m still on NodejsFunction
t

thdxr

01/20/2022, 8:22 PM
Wait
The default main fields depend on the current platform setting and are essentially browser,module,main for the browser and main,module for node.
This seems to suggest if you do
--platform=node
(which we do) it'll use
main,module
And I do think this is working because I think I saw stacktraces pointing to
esm
version of
kysely
m

Mischa Spiegelmock

01/20/2022, 8:28 PM
main is cjs
innit?
when i look at my bundle meta it shows cjs versions of everything being included
t

thdxr

01/20/2022, 8:35 PM
Yeah it's kind of confusing but here's how we publish both cjs and esm: https://github.com/serverless-stack/kysely-data-api/blob/master/package.json#L7 The
module: <>
syntax actually isn't part of the official node specification
Yeah I can verify calling esbuild gets the right files from two esm packages I use
kysely and @graphql-tools/schema
m

Mischa Spiegelmock

01/21/2022, 7:04 AM
esbuild is definitely for sure packaging CJS versions of my deps
and if I set --main-fields=module,main then it bundles the ES versions. i’m checking with the metafile and bundle buddy
t

thdxr

01/21/2022, 11:32 AM
Does cdk set the platform option
m

Mischa Spiegelmock

01/21/2022, 11:43 AM
yes
'--platform=node'
t

thdxr

01/21/2022, 2:10 PM
That is really strange, my metafile shows correct esm files
wonder if the CLI behaves different than using esbuild as a library
m

Mischa Spiegelmock

01/21/2022, 2:11 PM
just got my changes merged to CDK 🙂 https://github.com/aws/aws-cdk/pull/18569