From ebc4eb12084560516cb981e4a9e76b5165079c15 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sat, 5 Oct 2024 17:25:48 +0900 Subject: [PATCH] Fix build warning on Next.js' client rendering Address https://github.com/dahlia/logtape/issues/19 --- CHANGES.md | 5 +++++ logtape/fs.cjs | 12 +++++++----- logtape/nodeUtil.cjs | 12 +++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 482939a..e6bdc04 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Version 0.6.4 To be released. + - Fixed a build warning due to importing `node:fs` and `node:util` modules on + Next.js' client rendering. [[#19]] + +[#19]: https://github.com/dahlia/logtape/issues/19 + Version 0.6.3 ------------- diff --git a/logtape/fs.cjs b/logtape/fs.cjs index 40171ff..fe20ac6 100644 --- a/logtape/fs.cjs +++ b/logtape/fs.cjs @@ -1,10 +1,12 @@ let fs = null; if ( - "process" in globalThis && "versions" in globalThis.process && - "node" in globalThis.process.versions && - typeof globalThis.caches === "undefined" && - typeof globalThis.addEventListener !== "function" || - "Bun" in globalThis + typeof window === "undefined" && ( + "process" in globalThis && "versions" in globalThis.process && + "node" in globalThis.process.versions && + typeof globalThis.caches === "undefined" && + typeof globalThis.addEventListener !== "function" || + "Bun" in globalThis + ) ) { try { // Intentionally confuse static analysis of bundlers: diff --git a/logtape/nodeUtil.cjs b/logtape/nodeUtil.cjs index dc5c169..0984aff 100644 --- a/logtape/nodeUtil.cjs +++ b/logtape/nodeUtil.cjs @@ -1,10 +1,12 @@ let util = null; if ( - "process" in globalThis && "versions" in globalThis.process && - "node" in globalThis.process.versions && - typeof globalThis.caches === "undefined" && - typeof globalThis.addEventListener !== "function" || - "Bun" in globalThis + typeof window === "undefined" && ( + "process" in globalThis && "versions" in globalThis.process && + "node" in globalThis.process.versions && + typeof globalThis.caches === "undefined" && + typeof globalThis.addEventListener !== "function" || + "Bun" in globalThis + ) ) { try { // Intentionally confuse static analysis of bundlers: