Skip to content

[Bug]: File Transport does not work with Bun JS #2553

@adarshmadrecha

Description

@adarshmadrecha

🔎 Search Terms

File Transport, Bun js, mkdirSync

The problem

File Transport does not work on Bun if dirName is not provided.

What version of Winston presents the issue?

3.17.0

What version of Node are you using?

bun v1.2.16

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

No response

Minimum Working Example

import { createLogger,  transports } from "winston";

export const logger = createLogger({
  transports: [
    new transports.File({
      filename: "info.log",
      level: "info",
    }),
  ],
});

// This will never run on bun. 
logger.info("Am I alive?");

While this run fine.

import { createLogger,  transports } from "winston";

export const logger = createLogger({
  transports: [
    new transports.File({
      filename: "info.log",
      level: "info",
      dirname: 'apilog' // THIS IS REQUIRED TO OVERCOME the bun error. 
    }),
  ],
});

// This now run fine.
logger.info("Am I alive?");

Additional information

The error is

756 |   _createLogDirIfNotExist(dirPath) {
757 |     /* eslint-disable no-sync */
758 |     if (!fs.existsSync(dirPath)) {
759 |       fs.mkdirSync(dirPath, { recursive: true });
               ^
ENOENT: no such file or directory, mkdir
 syscall: "mkdir",
   errno: -2,
    code: "ENOENT"

      at _createLogDirIfNotExist (C:\Users\vanta\code\bun-test2\node_modules\winston\lib\winston\transports\file.js:759:10)
      at new File (C:\Users\vanta\code\bun-test2\node_modules\winston\lib\winston\transports\file.js:94:28)
      at C:\Users\vanta\code\bun-test2\index.ts:10:5

Related: oven-sh/bun#19090

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions