Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: transport is not a function #42

Open
brandonros opened this issue Feb 26, 2016 · 12 comments
Open

TypeError: transport is not a function #42

brandonros opened this issue Feb 26, 2016 · 12 comments

Comments

@brandonros
Copy link

log.js

var winston = require('winston');

require('winston-loggly');

winston.add(winston.transports.Loggly, {
    token: 'revoked',
    subdomain: 'revoked',
    tags: ['Winston-NodeJS'],
    json: true
});

module.exports = function (level, msg, metadata) {
    winston.log(level, msg, metadata);
};

Stack

TypeError: transport is not a function
     at Logger.add (/home/brandon/project/node_modules/winston/lib/winston/logger.js:475:41)
     at Object.winston.(anonymous function) [as add] (/home/brandon/project/node_modules/winston/lib/winston.js:87:34)
     at Object.<anonymous> (/home/brandon/project/lib/log.js:5:9)

I can't reproduce this on my development machine, but can reproduce it on my production servers.

@jcrugzz
Copy link
Contributor

jcrugzz commented Feb 26, 2016

@brandonros can you identify if there is a different version of winston or winston-loggly in dev compared to production?

@brandonros
Copy link
Author

There is not. I can 'ncu -a' and 'npm update' on both.

On Friday, February 26, 2016, Jarrett Cruger [email protected]
wrote:

@brandonros https://github.com/brandonros can you identify if there is
a different version of winston or winston-loggly in dev compared to
production?


Reply to this email directly or view it on GitHub
#42 (comment)
.

@jcrugzz
Copy link
Contributor

jcrugzz commented Feb 26, 2016

@brandonros try rm -rf node_modules/winston && rm -rf node_modules/winston-loggly && npm i to ensure its updating as expected

@brandonros
Copy link
Author

brandon@server:~/server$ rm -rf node_modules/winston && rm -rf node_modules/winston-loggly && npm i
[email protected] /home/brandon/server
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]
brandon@server:~/server$ node api_server/api_server.js
/home/brandon/server/node_modules/winston/lib/winston/logger.js:475
  var instance = created ? transport : (new (transport)(options));
                                        ^

TypeError: transport is not a function
    at Logger.add (/home/brandon/server/node_modules/winston/lib/winston/logger.js:475:41)
    at Object.winston.(anonymous function) [as add] (/home/brandon/server/node_modules/winston/lib/winston.js:87:34)
    at Object.<anonymous> (/home/brandon/server/lib/log.js:5:9)

@brandonros
Copy link
Author

It has something to do with me being a noob when it comes to module.exports and its behavior/caching, I think.

@tomarsamar
Copy link

tomarsamar commented May 16, 2016

@brandonros try using logger = require('morgan') along with winston, I am facing same problem if I remove morgan

var logger = require('morgan'), 
     winston = require('winston')

require('winston-loggly');

winston.add(winston.transports.Loggly, {
    token: 'revoked',
    subdomain: 'revoked',
    tags: ['Winston-NodeJS'],
    json: true
});

module.exports = function (level, msg, metadata) {
    winston.log(level, msg, metadata);
};

@kblcuk
Copy link

kblcuk commented Oct 18, 2016

@brandonros did you manage to solve this? Seeing the same issue. :/

@kblcuk
Copy link

kblcuk commented Oct 18, 2016

...found it out by myself eventually -- reason was in two different versions of winston library that npm decided to install: root node_modules had 2.1.1 version, and local had latest 2.2.0:

$ find . -type d -name winston
./node_modules/logger/node_modules/winston <-- my own logging module
<skip>
./node_modules/winston

Due to that and some require magic I don't quite understand, transport set by winston-loggly got set on a different instance of winston (root one) than the one used to set transport (in "logger")
the root one was installed due to prompt module explicitly requiring 2.1.x.

So in my case the "fix" was to explicitly require latest winston at the root of the package, which would then re-shuffle winston deps (storing local version in prompt rather than in root).

Hope this helps.

@lattice0
Copy link

Having the same problem as brandonros. When I place the code at index.js, everything runs, but when I place it in a module and require the module in index.js, I get the same error

@RobAWilkinson
Copy link

@LucasZanella I am getting the same issue as you, did you ever find a fix?

@AnthonyChiavelli
Copy link

Anybody ever solve this?

@yauri-io
Copy link

yauri-io commented Oct 3, 2017

I solved this by removing 'winston' and 'winston-loggly-bulk'
Then re-install 'winston' and 'winston-loggly-bulk' accordingly.

Before I was installing winston-loggly-bulk first then winston. Not sure if it is the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants