fix: improve path resolution compatibility
Update path resolution logic to handle both ESM and CJS environments safely, ensuring compatibility during build processes and runtime execution.
This commit is contained in:
parent
95f32a5c95
commit
29c086779b
1 changed files with 7 additions and 2 deletions
|
|
@ -9,8 +9,13 @@ import { AuthorData } from "./src/types.js";
|
|||
|
||||
dotenv.config();
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const currentFilename = typeof import.meta !== "undefined" && import.meta.url
|
||||
? fileURLToPath(import.meta.url)
|
||||
: (typeof __filename !== "undefined" ? __filename : "");
|
||||
|
||||
const currentDirname = typeof import.meta !== "undefined" && import.meta.url
|
||||
? path.dirname(currentFilename)
|
||||
: (typeof __dirname !== "undefined" ? __dirname : "");
|
||||
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
|
|
|||
Loading…
Reference in a new issue