[ts] Property 'createLogger' does not exist on type '{}'.
See original GitHub issuePlease 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.
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.
That fixes the compiler issues I was getting. However, I am still getting the errors Module Not Found Can't resolve 'fs' ...
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:15 (6 by maintainers)
Top GitHub Comments
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…
This worked for me in a test webpack project with the console transport. Good luck!
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’