-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in Next.js #11
Comments
I assume that it 's not working as expected. logtape/logtape/filesink.node.ts Lines 14 to 15 in 0ed9cb5
|
Which version of LogTape are you using? |
@dahlia I installed v0.5.0 using yarn. info All dependencies
└─ @logtape/logtape@0.5.0 |
It's not reproduced for me… Could you show me your next.config.mjs? |
@dahlia This doesn't seem to be a problem. I'll reproduce with new project. I initialized next project with /** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
images: {
unoptimized: true,
remotePatterns: [
{
protocol: 'https',
hostname: 'dummyimage.com',
port: '',
pathname: '/**',
},
],
},
assetPrefix: null,
experimental: {},
};
export default nextConfig; This is my installed packages(before installing logtape): {
"dependencies": {
"@dotenvx/dotenvx": "^1.11.1",
"@heroicons/react": "^2.1.5",
"@next/third-parties": "^14.2.5",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-radio-group": "^1.2.0",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@tanstack/react-table": "^8.20.1",
"chalk": "^5.3.0",
"class-variance-authority": "^0.7.0",
"classnames": "^2.5.1",
"clipboard": "^2.0.11",
"clsx": "^2.1.1",
"dayjs": "^1.11.12",
"eslint-plugin-prettier": "^5.2.1",
"lucide-react": "^0.427.0",
"next": "^14.2.8",
"next-themes": "^0.3.0",
"prettier": "^3.3.3",
"react": "^18.3.1",
"react-countup": "^6.5.3",
"react-d3-speedometer": "^2.2.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
"recharts": "^2.12.7",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"use-debounce": "^10.0.2",
"vaul": "^0.9.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "22.4.0",
"@types/react": "18.3.3",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"postcss": "^8",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.1",
"typescript": "5.5.4"
}
} |
Also facing this issue after adding export const LogtapeSetup: React.FunctionComponent = () => {
const loggerEnabled = useFeatureFlag('loggerEnabled');
// Using ref instead of state to avoid re-renders
const previouslyEnabledRef = React.useRef(false);
React.useLayoutEffect(() => {
if (loggerEnabled) {
previouslyEnabledRef.current = true;
void configure({
loggers: [
{ category: ['logtape', 'meta'], level: 'warning', sinks: ['console'] },
// TODO (Alexander Kachkaev) [2024-09-20]: Make feature flag more granular (allow to log only specific categories)
{ category: [], level: 'debug', sinks: ['console'] },
],
reset: true,
sinks: { console: getConsoleSink() },
});
} else if (previouslyEnabledRef.current) {
void configure({
loggers: [],
reset: true,
sinks: {},
});
}
}, [loggerEnabled]);
return <></>;
}; Here is the output from
Here is the output from
Has anyone found a workaround? |
I think I was able to
diff --git a/esm/formatter.js b/esm/formatter.js
index 1d735ed52a2b30eeda9dcab298acc83637f4a33d..94ddcda15b295f9d90285f3e7ff448f9eedd3aed 100644
--- a/esm/formatter.js
+++ b/esm/formatter.js
@@ -1,4 +1,3 @@
-import util from "node:util";
/**
* The severity level abbreviations.
*/
@@ -31,10 +30,13 @@ const inspect =
? globalThis.Deno.inspect.bind(globalThis.Deno)
// @ts-ignore: Node.js global
// dnt-shim-ignore
- : "inspect" in util && typeof util.inspect === "function"
+ // https://github.com/dahlia/logtape/issues/11
+ : "require" in globalThis
+ && "inspect" in globalThis.require("util")
+ && typeof globalThis.require("util").inspect === "function"
// @ts-ignore: Node.js global
// dnt-shim-ignore
- ? util.inspect.bind(util)
+ ? globalThis.require("util").inspect.bind(globalThis.require("util"))
: (v) => JSON.stringify(v);
/**
* The default text formatter. This formatter formats log records as follows:
diff --git a/esm/fs.js b/esm/fs.js
index 3e9d1edfc286044d35eca3430be81150efc66ac5..d28b75a367273ed3c8653b2ebfbda14a590ded89 100644
--- a/esm/fs.js
+++ b/esm/fs.js
@@ -7,7 +7,8 @@ if (
"Bun" in globalThis
) {
try {
- fs = await import("node" + ":fs");
+ // https://github.com/dahlia/logtape/issues/11
+ fs = globalThis.require(["node", "fs"].join(":"));
} catch (e) {
if (e instanceof TypeError) {
fs = null;
diff --git a/script/formatter.js b/script/formatter.js
index e137bdb7486289ad436b15d7d07c65d333ed6986..1082e1f0d3636465202b6da0613114e11c37cbf3 100644
--- a/script/formatter.js
+++ b/script/formatter.js
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ansiColorFormatter = void 0;
exports.defaultTextFormatter = defaultTextFormatter;
exports.defaultConsoleFormatter = defaultConsoleFormatter;
-const node_util_1 = __importDefault(require("node:util"));
+const node_util_1 = __importDefault(require(["node", "util"].join(":")));
/**
* The severity level abbreviations.
*/
diff --git a/script/fs.js b/script/fs.js
index bcb0170234994e2e0d6947738d5dffd9375526e7..938d78910905965428f8f781b2366510ebb00675 100644
--- a/script/fs.js
+++ b/script/fs.js
@@ -7,7 +7,8 @@ if (
"Bun" in globalThis
) {
try {
- fs = require("node" + ":fs");
+ // https://github.com/dahlia/logtape/issues/11
+ fs = require(["node", "fs"].join(":"));
} catch (_) {
fs = null;
} Key points:
I guess that it’s also possible to achieve something similar via custom webpack config inside What are the downsides of injecting something similar into logtape, so that the patch is no longer needed? Next.js is quite popular, so fixing this issue would be great for logtape’s adoption. |
Could you try LogTape v0.6.1? It fixed several bugs on Vite build, and these fixes might work for Next.js too. |
Thanks for the fix @dahlia! I tried 0.6.1 just now. The app compiles, but I get this warning in both
This warning on Stack Overflow: https://stackoverflow.com/q/42908116/1818285 It did not show up in 0.5.1 with my patch. Running |
This local patch helped with mitigating a new Webpack warning:
diff --git a/esm/nodeUtil.cjs b/esm/nodeUtil.cjs
index 4bf836e692bf4bf2c9f7706f56a959f30e088fbb..8cd834fd267a5489e05bf1d970535a52477104a5 100644
--- a/esm/nodeUtil.cjs
+++ b/esm/nodeUtil.cjs
@@ -7,7 +7,7 @@ if (
"Bun" in globalThis
) {
try {
- util = require(["node", "util"].join(":"));
+ util = require(`${["node", "util"].join(":")}`);
} catch (_) {
util = null;
} Source: https://stackoverflow.com/a/73359606/1818285. Interestingly, |
0.6.2 works like a charm with no warnings in Next.js! I guess we can close this issue 🎉 |
Summary
node:fs
andhydration
Log
Screenshot
The text was updated successfully, but these errors were encountered: