pinojs/pino

Cannot read properties of undefined (reading 'log')

issam-seghir opened this issue · 1 comments

  • server.js
// add alias
require("module-alias/register");

const express = require("express");
const pino = require("pino-http")();
....

const PORT = process.env.PORT || 3000;

const app = express();

// pino logger
app.use(
	pino({
		transport: {
			target: "pino-pretty",
		},
	})
);
  • package.json
	"scripts": {
		"dev": "node --watch --env-file=.env.development.local  server.js | pino-pretty",
		"prod": "node --watch --env-file=.env  server.js",
	},
...\server\node_modules\pino-http\logger.js:153     
if (!res.log) {             
 ^  TypeError: Cannot read properties of undefined (reading 'log')     at loggingMiddleware 
 (E:\Documents\Vs Code\My app\server\node_modules\pino-http\logger.js:153:14)     
 at result (E:\Documents\Vs Code\My app\server\node_modules\pino-http\logger.js:89:12)     at Object.<anonymous>
  (E:\Documents\Vs Code\My app\server\server.js:44:2)     at Module._compile (node:internal/modules/cjs/loader:1376:14)     at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)     at Module.load (node:internal/modules/cjs/loader:1207:32)     at Module._load (node:internal/modules/cjs/loader:1023:12)    
   at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)     at node:internal/main/run_main_module:28:49
     Node.js v20.10.0

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.