← All tasks
javascriptwinstonjs/winston #2327Not a task: already works

[Bug]: Winston failed to execute caused by TypeError

envgap__winstonjs__winston-2327

01 / FAILURE SIGNATURE

As reported upstream

The error message reflects a TypeError in [https://github.com/DABH/colors.js/blob/master/lib/system/has-flag.js](https://github.com/DABH/colors.js/blob/master/lib/system/has-flag.js) file. Not checks the argv variable is not undefined.
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
914b846846c5970711b5cba609dfbeb42c8580a7
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

winstonjs/winston #2327 · read the original issue
### 🔎 Search Terms



winston colors, winston docker container fails,



### The problem



**Winston version:** _^3.10.0_

**NodeJS version:** _v18.16.1_

**NPM version:** _9.5.1_

**NextJS version:** _13.4.10_





Winston brakes the app (NextJS 13) because of an unhandled Exception in peer dependency ([@colors/colors](https://github.com/DABH/colors.js/tree/master)):

The error message reflects a TypeError in [https://github.com/DABH/colors.js/blob/master/lib/system/has-flag.js](https://github.com/DABH/colors.js/blob/master/lib/system/has-flag.js) file. Not checks the argv variable is not undefined.

```

- error Error [TypeError]: Cannot read properties of undefined (reading 'indexOf')

2023-07-16T11:08:15.194016114Z     at <unknown> (webpack-internal:///(middleware)/./node_modules/@colors/colors/lib/system/has-flag.js:26)

2023-07-16T11:08:15.194019984Z     at module.exports (webpack-internal:///(middleware)/./node_modules/@colors/colors/lib/system/has-flag.js:26:30)

2023-07-16T11:08:15.194023256Z     at eval (webpack-internal:///(middleware)/./node_modules/@colors/colors/lib/system/supports-colors.js:29:5)

2023-07-16T11:08:15.194026264Z     at (middleware)/./node_modules/@colors/colors/lib/system/supports-colors.js (file:///app/_next/server/src/middleware.js:219:1)

2023-07-16T11:08:15.194029419Z     at __webpack_require__ (file:///app/_next/server/edge-runtime-webpack.js:37:33)

2023-07-16T11:08:15.194032354Z     at fn (file:///app/_next/server/edge-runtime-webpack.js:268:21)

2023-07-16T11:08:15.194035257Z     at eval (webpack-internal:///(middleware)/./node_modules/@colors/colors/lib/colors.js:36:25)

2023-07-16T11:08:15.194038400Z     at (middleware)/./node_modules/@colors/colors/lib/colors.js (file:///app/_next/server/src/middleware.js:127:1)

2023-07-16T11:08:15.194041466Z     at __webpack_require__ (file:///app/_next/server/edge-runtime-webpack.js:37:33)

2023-07-16T11:08:15.194044377Z     at fn (file:///app/_next/server/edge-runtime-webpack.js:268:21)

2023-07-16T11:08:15.194047214Z     at eval (webpack-internal:///(middleware)/./node_modules/@colors/colors/safe.js:9:14) {

2023-07-16T11:08:15.194050136Z   digest: undefined

2023-07-16T11:08:15.194052928Z }

```







### What version of Winston presents the issue?



3.10.0



### What version of Node are you using?



v18.16.11



### If this worked in a previous version of Winston, which was it?



_No response_



### Minimum Working Example



**1. Fresh install NextJS with Tailwind CSS**

```bash

npx create-next-app winston

Need to install the following packages:

  create-next-app@13.4.10

Ok to proceed? (y) y

✔ Would you like to use TypeScript? …  Yes

✔ Would you like to use ESLint? … No

✔ Would you like to use Tailwind CSS? … Yes

✔ Would you like to use `src/` directory? … Yes

✔ Would you like to use App Router? (recommended) … Yes

✔ Would you like to customize the default import alias? … No

```



**2. Install the latest version of Winston**

```bash

npm install winston

```

**3. Make a logger instance in `src/services/logger.ts` file**

```ts

import winston from 'winston';



const logger = winston.createLogger({

  level: 'debug',

  transports: [new winston.transports.Console()],

  format: winston.format.json(),

});

export default logger;

```

**4. Create NextJS middleware in `src/middleware.ts` file**

```ts

import { NextResponse } from 'next/server';

import type { NextRequest } from 'next/server';



import logger from '@/services/logger';



export const config = {

  matcher: '/',

}



export function middleware(request: NextRequest) {



  if(request === undefined){

    return NextResponse.json({

      message: "Bad request"

    }, {

      status: 400,

    })

  }



  const testHeader = 'script-src \'self\';';



  if(testHeader.includes('default-src') === false){

    logger.error("Header values mismatch!")

  }



  const response = NextResponse.next();

  response.headers.set('Content-Security-Policy', testHeader);

  return response;

}

```

**5. Start the app**

```bash

npm run dev

```

**After that the error (which is detailed above) has appeared in the console and the browser.**



# Additional configs



## package.json

```json

{

  "name": "winston",

  "version": "0.1.0",

  "private": true,

  "scripts": {

    "dev": "next dev",

    "build": "next build",

    "start": "next start",

    "lint": "next lint"

  },

  "dependencies": {

    "@types/node": "20.4.2",

    "@types/react": "18.2.15",

    "@types/react-dom": "18.2.7",

    "autoprefixer": "10.4.14",

    "next": "13.4.10",

    "postcss": "8.4.26",

    "react": "18.2.0",

    "react-dom": "18.2.0",

    "tailwindcss": "3.3.3",

    "typescript": "5.1.6",

    "winston": "^3.10.0"

  }

}

```

## tsconfig.json

**Not modified manually, generated by `npx create-next-app`**

```json

{

  "compilerOptions": {

    "target": "es5",

    "lib": ["dom", "dom.iterable", "esnext"],

    "allowJs": true,

    "skipLibCheck": true,

    "strict": true,

    "forceConsistentCasingInFileNames": true,

    "noEmit": true,

    "esModuleInterop": true,

    "module": "esnext",

    "moduleResolution": "node",

    "resolveJsonModule": true,

    "isolatedModules": true,

    "jsx": "preserve",

    "incremental": true,

    "plugins": [

      {

        "name": "next"

      }

    ],

    "paths": {

      "@/*": ["./src/*"]

    }

  },

  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],

  "exclude": ["node_modules"]

}

```

## next.config.js

**Not modified manually, generated by `npx create-next-app`**

```js

/** @type {import('next').NextConfig} */

const nextConfig = {}



module.exports = nextConfig

```



## Directory structure and permissions

```bash

drwxrwxr-x   7 adam adam 4,0K júl   16 14:16 .

drwxr-xr-x   8 adam adam 4,0K júl   16 14:12 ..

drwxrwxr-x   8 adam adam 4,0K júl   16 14:13 .git

-rw-rw-r--   1 adam adam  368 júl   16 14:11 .gitignore

drwxrwxr-x   6 adam adam 4,0K júl   16 14:47 .next

-rw-rw-r--   1 adam adam   92 júl   16 14:11 next.config.js

-rw-rw-r--   1 adam adam  201 júl   16 14:11 next-env.d.ts

drwxrwxr-x 133 adam adam 4,0K júl   16 14:17 node_modules

-rw-rw-r--   1 adam adam  514 júl   16 14:17 package.json

-rw-rw-r--   1 adam adam  63K júl   16 14:17 package-lock.json

-rw-rw-r--   1 adam adam   82 júl   16 14:11 postcss.config.js

drwxrwxr-x   2 adam adam 4,0K júl   16 14:12 public

-rw-rw-r--   1 adam adam 1,4K júl   16 14:11 README.md

drwxrwxr-x   4 adam adam 4,0K júl   16 14:24 src

-rw-rw-r--   1 adam adam  480 júl   16 14:12 tailwind.config.js

-rw-rw-r--   1 adam adam  642 júl   16 14:12 tsconfig.json

```



### Additional information



_No response_
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]