question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ts] Property 'createLogger' does not exist on type '{}'.

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs:
  • Operating System? macOS
  • Language? ASP.NET Core, TypeScript 2.9.1, es5, ReactJS

What is the problem?

After installing ASP.NET Core with React.js

dotnet new react

And add the getting-started example for either winston3 or winston2 on Home.tsx

import * as React from 'react';
import { RouteComponentProps } from 'react-router';
const winston = require('winston');
const logger = winston.createLogger({
    transports: [
         new winston.transports.Console(),
        new winston.transports.File({ filename: 'combined.log' })
    ]
 });

 logger.log({
     level: 'info',
     message: 'Hello distributed log files!'
 });

I’m seeing compilation errors from TypeScript. winston-errors

What do you expect to happen instead?

I’m expecting to be able to log to Console and File.

{"level":"info","message":"Hello distributed log files!"}

Other information

My tsconfig.json:
{
    "compilerOptions": {
    "baseUrl": ".",
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "jsx": "react",
    "sourceMap": true,
    "skipDefaultLibCheck": true,
    "strict": true,
    "types": ["webpack-env"]
 },
 "exclude": [
    "bin",
    "node_modules"
  ]
}

I can fix the TypeScript error by defining

const winstonType: any = winston;

const logger = winstonType.createLogger({
    transports: [
       new winstonType.transports.Console(),
       new winstonType.transports.File({ filename: 'combined.log' })
   ]
});

But then get errors:

Module not found: Error: Can't resolve 'fs' in '/hello-logging-winston/node_modules/winston/lib/winston' Module not found: Error: Can't resolve 'fs' in '/hello-logging-winston/node_modules/winston/lib/winston/transports'

I’ve since found that ReactJS is not supported but is on the v3 roadmap. According to https://github.com/winstonjs/winston/issues/900, I must use import * as winston from 'winston' in order to get all exports. winston-errors-3 0

That fixes the compiler issues I was getting. However, I am still getting the errors Module Not Found Can't resolve 'fs' ...

winston-errors-3 0-browser

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
DABHcommented, Jun 13, 2018

Btw if you add the following to your webpack config, it seems the console transport at least works. But the point is you just ignore the fs module…

node: {
    fs: 'empty'
}

This worked for me in a test webpack project with the console transport. Good luck!

0reactions
ArpithaGMGowdacommented, Feb 21, 2020

i am getting this error .

ERROR in ./node_modules/winston/dist/winston/tail-file.js Module not found: Error: Can’t resolve ‘fs’ in ‘C:\Users\703247433\Desktop\winstontoolkit\toolkit\node_modules\winston\dist\winston’ ERROR in ./node_modules/winston/dist/winston/transports/file.js Module not found: Error: Can’t resolve ‘fs’ in ‘C:\Users\703247433\Desktop\winstontoolkit\toolkit\node_modules\winston\dist\winston\transports’

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winston custom log levels typescript definitions - Stack Overflow
Logger and the ts says [ts] Property 'protocol' does not exist on type 'Logger'. [2339] . Typescript doesn't know about my levels. How...
Read more >
How to fix 'Property does not exist on type Window in ...
Creating an index.d.ts file somewhere in our project. Editing the file to define the types on the Window object. (optional) adding ...
Read more >
winston - npm
A multi-transport async logging library for Node.js. Latest version: 3.8.2, last published: 4 months ago. Start using winston in your ...
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
Winston is available as an npm package, so you can install it through the ... property in the configuration object passed to the...
Read more >
Fix - Property does not exist on type '{}' in TypeScript
ts (2339) object1.name = 'Justice';. From the above, suppose the 'object1' is a JSON data that is coming from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found