From 225f1e3aa3cfe20b8d112e6ccdaaf562f66ef7b8 Mon Sep 17 00:00:00 2001 From: yzh990918 <251205668@qq.com> Date: Tue, 28 Mar 2023 19:18:00 +0800 Subject: [PATCH] fix(template): __dirname is not defined in ES module scope --- .env.example | 6 ++++++ packages/templates/src/enum.ts | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..54f7392 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# https://www.mongodb.com/atlas/database +API_KEY=xxx +API_BASE_URL=xxx +DATASOURCE=xxx +DATABASE=xxx +COLLECTION=xxx diff --git a/packages/templates/src/enum.ts b/packages/templates/src/enum.ts index dc3e59f..1849310 100644 --- a/packages/templates/src/enum.ts +++ b/packages/templates/src/enum.ts @@ -1,7 +1,11 @@ import path from 'path' +import { fileURLToPath } from 'url' import dotenv from 'dotenv' +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + dotenv.config({ path: path.resolve(__dirname, '../../../.env'), })