With <this patch> I’m able to build/deploy my proj...
# help
m
With this patch I’m able to build/deploy my project on 0.53.0 But on 0.55.0 I cannot:
Copy code
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/cyber/dev/platform/packages/infra/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/cyber/dev/platform/packages/infra/.sst/artifacts/1d3e06ae/builder.js:2:25
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
    at Object.bundle (/Users/cyber/dev/serverless-stack/packages/core/dist/runtime/handler/node.js:198:23)
    at Object.bundle (/Users/cyber/dev/serverless-stack/packages/core/dist/runtime/handler/handler.js:19:16)
    at new Function (/Users/cyber/dev/serverless-stack/packages/resources/src/Function.ts:359:39)
    at Function.fromDefinition (/Users/cyber/dev/serverless-stack/packages/resources/src/Function.ts:528:14)
    at PlatformApi.addResolver (/Users/cyber/dev/serverless-stack/packages/resources/src/AppSyncApi.ts:376:19)
    at /Users/cyber/dev/serverless-stack/packages/resources/src/AppSyncApi.ts:203:23
    at Array.forEach (<anonymous>)
    at PlatformApi.addResolvers (/Users/cyber/dev/serverless-stack/packages/resources/src/AppSyncApi.ts:201:28)
    at new VacancyService (/Users/cyber/dev/platform/packages/infra/lib/service/vacancy.ts:23:13)
    at new ApiServices (/Users/cyber/dev/platform/packages/infra/lib/service/apiServices.ts:68:5)
t
can you try doing that into the
.sst
folder - I moved artifacts into there
Might need to do it in both, we're in the process of moving everything to the
.sst
folder
m
ok. what should this be then?
const buildPackageJsonPath = path.join(paths.appBuildPath, "package.json");
buildDir?
t
Do you need this per function? If so I'd maybe add a patch to runtime/handler/node.ts - there's a build function for local dev and bundle function for prod. You can write a package.json there
Copy code
const package = path.join(artifact, "package.json");
m
I’ve got this problem now:
Copy code
This file is being treated as an ES module because it has a '.js' file extension and '/Users/cyber/dev/platform/packages/infra/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/cyber/dev/platform/packages/infra/.sst/artifacts/1d3e06ae/builder.js:2:25
because my infra package is in a subfolder?
t
Hm it should be hitting an earlier package.json right?
but yeah there's some weird issues if you make your infra its own package
m
i do not need ESM building per-function
t
ahh ok I see the issue one second
In
handler/node.ts
see how I write a temporary builder script
rewrite that to be esm
m
👀
t
probably just turn the require(esbuild) to an import
m
code generation is the root of all evil bro
t
yeah I know 🤦🏽‍♂️
We have a plan to get rid of this workaround
Unfortunately CDK is all constructor based which means you can't have any async code, esbuild doesn't support sync so we had to work around it by spawning a script
m
i sure hope cdk2 contains support for deferred asset compilation but i’m guessing it doesn’t
would be nice to return a
Promise<Code>
and carry on
ok changing require to import helped in node.js thanks
t
we're going to create a framework for doing deferred compilation outside of cdk
Builds are way too slow when people have even 20 functions since they can't be parallelized meaningfully
m
yeah totally for sure. are you on the cdk slack? happy to start pushing it there
why is it closed… ? i don’t know
i’m ready to throw down my hoe and pick up an ak
t
lol
Yeah it is frustrating being subject to CDK and CFN limitations
m