From 79d8f695edd579f45b0ad191b0d7ba92dc6093d6 Mon Sep 17 00:00:00 2001 From: printfn Date: Sat, 7 Dec 2024 05:37:28 +0000 Subject: [PATCH] Try using ESM for telegram bot --- telegram-bot/build.sh | 8 ++++---- telegram-bot/index.ts | 2 +- telegram-bot/tsconfig.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/telegram-bot/build.sh b/telegram-bot/build.sh index d504f19c..19f19935 100755 --- a/telegram-bot/build.sh +++ b/telegram-bot/build.sh @@ -2,15 +2,15 @@ set -euo pipefail cd "$(dirname "$0")" -(cd ../wasm && wasm-pack build --target nodejs --out-dir pkg-nodejs) +(cd ../wasm && wasm-pack build --out-dir pkg-nodejs) echo "Renaming package to 'fend-wasm-nodejs'..." jq "setpath([\"name\"]; \"fend-wasm-nodejs\")" ../wasm/pkg-nodejs/package.json >temp mv temp ../wasm/pkg-nodejs/package.json npm install npm exec tsc -npm exec -- esbuild --bundle index.ts --outdir=dist --platform=node +npm exec -- esbuild --bundle index.ts --outdir=dist --platform=node --format=esm --loader:.wasm=binary rm -f lambda_package.zip -# don't include package.json because esbuild makes a CJS bundle that won't work if node finds `"type": "module"` -zip -j lambda_package.zip dist/index.js node_modules/fend-wasm-nodejs/fend_wasm_bg.wasm + +zip -j lambda_package.zip package.json dist/index.js diff --git a/telegram-bot/index.ts b/telegram-bot/index.ts index 06565963..d706b2e4 100644 --- a/telegram-bot/index.ts +++ b/telegram-bot/index.ts @@ -1,4 +1,4 @@ -import fend from 'fend-wasm-nodejs'; +import * as fend from 'fend-wasm-nodejs'; const TELEGRAM_BOT_API_TOKEN = process.env.TELEGRAM_BOT_API_TOKEN; diff --git a/telegram-bot/tsconfig.json b/telegram-bot/tsconfig.json index 9bba3ebb..67b9d176 100644 --- a/telegram-bot/tsconfig.json +++ b/telegram-bot/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", + "module": "NodeNext", + "moduleResolution": "NodeNext", "allowSyntheticDefaultImports": true, "strict": true, "noEmit": true