Adrián Mouly
06/06/2022, 7:31 PMReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/amouly/Projects/yabble/yabble-serverless/.build/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
thdxr
06/06/2022, 7:31 PM__dirname
somewherethdxr
06/06/2022, 7:32 PMAdrián Mouly
06/06/2022, 7:33 PMAdrián Mouly
06/06/2022, 7:33 PMAdrián Mouly
06/06/2022, 7:35 PMthdxr
06/06/2022, 7:36 PM__dirname
. Can you send me .build/lib/index.js
thdxr
06/06/2022, 7:36 PMAdrián Mouly
06/06/2022, 7:36 PMthdxr
06/06/2022, 7:36 PMAdrián Mouly
06/06/2022, 7:37 PMReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/amouly/Projects/yabble/yabble-serverless/.build/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at node_modules/app-root-path/index.js (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:100493:27)
at __require2 (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:18:50)
at node_modules/typeorm/connection/ConnectionOptionsReader.js (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:112285:51)
at __require2 (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:18:50)
at node_modules/typeorm/globals.js (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:161892:37)
at __require2 (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:18:50)
at node_modules/typeorm/index.js (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:163944:26)
at __require2 (file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:18:50)
at file:///Users/amouly/Projects/yabble/yabble-serverless/.build/lib/index.js:796582:28
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
at async file:///Users/amouly/Projects/yabble/yabble-serverless/.build/run.mjs:85:17
Reading cached notices from /Users/amouly/.cdk/cache/notices.json
thdxr
06/06/2022, 7:37 PMAdrián Mouly
06/06/2022, 7:37 PMthdxr
06/06/2022, 7:37 PM.build/lib/index.js
should be pretty smallAdrián Mouly
06/06/2022, 7:38 PMAdrián Mouly
06/06/2022, 7:38 PMthdxr
06/06/2022, 7:40 PMesbuild --minify --external:"@serverless-stack/*" --bundle --format=esm --target=esnext --platform=node ./stacks/index.ts --analyze=verbose
Adrián Mouly
06/06/2022, 7:41 PMthdxr
06/06/2022, 7:41 PMAdrián Mouly
06/06/2022, 7:43 PMAdrián Mouly
06/06/2022, 7:43 PMAdrián Mouly
06/06/2022, 7:43 PMAdrián Mouly
06/06/2022, 7:43 PM├ node_modules/typeorm/decorator/options/JoinTableOptions.js ───────────────────────────────────────────────────── 82b ──── 0.0%
│ └ node_modules/typeorm/index.js
│ └ node_modules/typeorm/index.mjs
│ └ packages/src/data/mySqlDatabaseConnection.ts
│ └ packages/src/data/index.ts
│ └ packages/src/common/middleware/databaseMiddy.ts
│ └ packages/src/common/index.ts
│ └ infrastructure/src/yabble/surveyResponses/YabbleSurveyResponsesIngestionMetadataStack.ts
│ └ infrastructure/src/yabble/Yabble.ts
│ └ infrastructure/src/index.ts
thdxr
06/06/2022, 7:43 PMAdrián Mouly
06/06/2022, 7:43 PMAdrián Mouly
06/06/2022, 7:44 PMthdxr
06/06/2022, 7:44 PMAdrián Mouly
06/06/2022, 7:44 PMthdxr
06/06/2022, 7:44 PMcommon/index.ts
it'll include everything in there even if you're just importing 1 thingAdrián Mouly
06/06/2022, 7:44 PMthdxr
06/06/2022, 7:44 PMAdrián Mouly
06/06/2022, 7:44 PMAdrián Mouly
06/06/2022, 7:44 PMthdxr
06/06/2022, 7:45 PMimport { Thing } from "common/thing.js"
instead of import { Thing } from "common"
Adrián Mouly
06/06/2022, 7:45 PMAdrián Mouly
06/06/2022, 7:45 PMAdrián Mouly
06/06/2022, 7:45 PMthdxr
06/06/2022, 7:45 PMAdrián Mouly
06/06/2022, 7:46 PMAdrián Mouly
06/06/2022, 7:46 PMAdrián Mouly
06/06/2022, 7:46 PMthdxr
06/06/2022, 7:49 PMAdrián Mouly
06/06/2022, 7:50 PMAdrián Mouly
06/06/2022, 7:50 PMAdrián Mouly
06/06/2022, 7:50 PMthdxr
06/06/2022, 7:50 PMAdrián Mouly
06/06/2022, 7:50 PMthdxr
06/06/2022, 7:50 PMAdrián Mouly
06/06/2022, 7:50 PMAdrián Mouly
06/06/2022, 7:51 PMre-exports
? having them exported again from the index.ts
in a sub-folder?Adrián Mouly
06/06/2022, 7:51 PMindex.ts
in my shared-packages?Adrián Mouly
06/06/2022, 7:56 PMAdrián Mouly
06/06/2022, 7:56 PMAdrián Mouly
06/06/2022, 7:57 PMimport { BaseError, ErrorType, Logger, COMMON } from '@yabble/packages-common';
Ross Coundon
06/06/2022, 8:15 PMAdrián Mouly
06/06/2022, 8:16 PMAdrián Mouly
06/06/2022, 8:16 PMAdrián Mouly
06/06/2022, 8:16 PMRoss Coundon
06/06/2022, 8:16 PMAdrián Mouly
06/06/2022, 8:17 PMAdrián Mouly
06/06/2022, 8:17 PMRoss Coundon
06/06/2022, 8:17 PMAdrián Mouly
06/06/2022, 8:17 PMRoss Coundon
06/06/2022, 8:17 PMAdrián Mouly
06/06/2022, 8:17 PMRoss Coundon
06/06/2022, 8:18 PMAdrián Mouly
06/06/2022, 8:20 PMthdxr
06/06/2022, 8:23 PMthdxr
06/06/2022, 8:23 PMthdxr
06/06/2022, 8:23 PMAdrián Mouly
06/06/2022, 8:23 PMAdrián Mouly
06/06/2022, 8:23 PMthdxr
06/06/2022, 8:24 PMthdxr
06/06/2022, 8:24 PMAdrián Mouly
06/06/2022, 8:24 PMAdrián Mouly
06/06/2022, 8:24 PMAdrián Mouly
06/06/2022, 8:25 PMAdrián Mouly
06/06/2022, 8:42 PMAdrián Mouly
06/06/2022, 8:42 PMthdxr
06/06/2022, 8:43 PMAdrián Mouly
06/06/2022, 8:43 PMAdrián Mouly
06/06/2022, 8:43 PMAdrián Mouly
06/06/2022, 8:44 PMAdrián Mouly
06/06/2022, 8:44 PMAdrián Mouly
06/06/2022, 8:47 PMAdrián Mouly
06/06/2022, 8:58 PMAdrián Mouly
06/06/2022, 8:58 PMthdxr
06/06/2022, 8:59 PMAdrián Mouly
06/06/2022, 9:01 PMAdrián Mouly
06/06/2022, 9:01 PMAdrián Mouly
06/06/2022, 9:02 PMMischa Spiegelmock
06/07/2022, 2:19 AMthdxr
06/07/2022, 2:20 AMMischa Spiegelmock
06/07/2022, 2:20 AMconst ESM_REQUIRE_SHIM = `await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname=e(globalThis.__filename)),typeof globalThis.require>"u"){let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();`
// use this to build lambdas as ESM
const esmBundlingDefaults: Partial<FunctionBundleProp> = {
format: "esm",
mainFields: ["module", "main"], // prefer ESM versions of libraries
banner: ESM_REQUIRE_SHIM,
}
which worked pretty great but i dunno how to do it with SST bundle optionsthdxr
06/07/2022, 2:20 AMMischa Spiegelmock
06/07/2022, 2:21 AMthdxr
06/07/2022, 2:21 AMMischa Spiegelmock
06/07/2022, 2:21 AMthdxr
06/07/2022, 2:22 AMthdxr
06/07/2022, 2:22 AMMischa Spiegelmock
06/07/2022, 2:22 AMMischa Spiegelmock
06/07/2022, 2:22 AMthdxr
06/07/2022, 2:22 AMthdxr
06/07/2022, 2:23 AMMischa Spiegelmock
06/07/2022, 2:23 AMMischa Spiegelmock
06/07/2022, 2:23 AMbanner
option?
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html#bannerthdxr
06/07/2022, 2:24 AMthdxr
06/07/2022, 2:24 AMAdrián Mouly
06/07/2022, 2:37 AMMischa Spiegelmock
06/07/2022, 3:20 AM