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

No such native module with winstonjs/winston #178

Closed
pinodex opened this issue Feb 4, 2016 · 15 comments
Closed

No such native module with winstonjs/winston #178

pinodex opened this issue Feb 4, 2016 · 15 comments

Comments

@pinodex
Copy link

pinodex commented Feb 4, 2016

I get this error when I run the compiled application.

nexe.js:1129
    var doParallelLimit = function(limit, fn) {
                            ^

Error: No such native module ./transports/console
    at NativeModule.require (node.js:932:13)
    at s (nexe.js:1:176)
    at nexe.js:1:367
    at Object.Console (nexe.js:66028:12)
    at new exports.Container (nexe.js:65162:29)
    at Object.__dirname.259../winston/common (nexe.js:64514:19)
    at s (nexe.js:1:316)
    at nexe.js:1:367
    at Object.__dirname.175.events (nexe.js:47558:15)
    at s (nexe.js:1:316)

The file that might be triggering the error is https://github.com/winstonjs/winston/blob/0.8.3/lib/winston/transports.js#L32

I tried the following to workaround the dynamic requires:

In the file where I call nexe.compile(), I added a code before that to create a file on the same directory as transports.js. The file contains:

require('./transports/console');
require('./transports/daily-rotate-file');
require('./transports/file');
require('./transports/http');
require('./transports/memory');
require('./transports/transport');
require('./transports/webhook');

Then that file is required at my main file:

var _nexeDynamicBundle = false;

if (_nexeDynamicBundle) {
  require('winston/lib/winston/nexe-bundle');
}

And also, the generated binary file contains the required files as what I saw in output.exe/.rdata:

},{"./common":260,"fs":undefined,"path":undefined}],270:[function(require,module,exports){
/*
 * console.js: Transport for outputting to the console
 *
 * (C) 2010 Charlie Robbins
 * MIT LICENCE
 *
 */
},{"./transports/console":270,"./transports/daily-rotate-file":271,"./transports/file":272,"./transports/http":273,"./transports/memory":274,"./transports/transport":275,"./transports/webhook":276}],269:[function(require,module,exports){

Any idea why the error occurs?

@jaredallard
Copy link
Member

Hi! This is a common issue at the moment, I'd revert to 0.4.7 and see if that solves your problem for now-- if not, then you'll have to wait!

Browserify has some kinks at the moment, and solves some other ones. It's a bit off a difficult setup at the moment.

@jaredallard
Copy link
Member

I'd have a go at master and see if the new package.json options:

browserify.exclude
browserify.requires
browserify.paths

and see if any of those help you, specifically paths. (adds the the lookup array for require.resolve)

@Kurtas
Copy link

Kurtas commented Mar 17, 2016

Same problem even I'm using master

Cannot find module 'hiredis' from '/home/user/discovery/node_modules/ioredis/lib/parsers'

my package.json setting

  "nexe": {
    "browserify": {
        "requires": [],
        "excludes": ["hiredis"],
        "paths": []
    }
  },

When I tried to use nexe verison 0.4.1 then it is compiled ok, but bin doesn't work (same problem as above with winston transports which are lazy loaded)

  return binding.readdir(pathModule._makeLong(path));
                 ^

Error: ENOENT: no such file or directory, scandir '/home/user/discovery/transports'
    at Error (native)
    at Object.fs.readdirSync (fs.js:813:18)
    at Array.__dirname.call./home/user/discovery/node_modules/winston/lib/winston/transports.js.fs (nexe.js:37081:4)
    at initModule (nexe.js:29:11)
    at nexe.js:31:64
    at Array.__dirname.call./home/user/discovery/node_modules/winston/lib/winston.js../winston/transports/transport (nexe.js:7851:22)
    at initModule (nexe.js:29:11)
    at nexe.js:31:64
    at Object.e.__esModule.default (nexe.js:47:3355)
    at t (nexe.js:47:107)

What about switch browserify to webpack, as I know webpack can handle a lazy loading modules.

@jaredallard
Copy link
Member

I'll look into webpack!

@jaredallard
Copy link
Member

@Kurtas I've been looking into webpack. It works for most of the tests, but for big projects it doesn't seem to work. Specifically express (test/express-test).

If it's just my configuration then please try it out and see if you can figure anything out, thanks!

module.exports = {
    context: __dirname,
    target: 'node',
    entry: "./bin/www", //entry point
    module: {
        loaders: [
            {
                test: /\.json$/,
                loader: "json-loader" 
            }
        ]
    }
}

@calvin
Copy link

calvin commented Jul 19, 2016

@gbaumgart Can you elaborate your comment? What do you mean by:

I usually fix this by placing such modules beside the binary in node_modules.

@calvin
Copy link

calvin commented Jul 19, 2016

@gbaumgart Thanks for your comments. I ended up writing a workaround which loads required transport files statically.

@thekiba
Copy link

thekiba commented Aug 5, 2016

@calvin Hello, i have a same issue. Can you talk about your solution?

@calvin
Copy link

calvin commented Aug 9, 2016

@thekiba It was done in a quick-and-dirty manner hence not fully tested.

https://gist.github.com/calvin/f72be59338ccbaefb5f9617d33fe2e3a

@thekiba
Copy link

thekiba commented Aug 9, 2016

@calvin aha, i see. So i found another solution. Check issue #243

@syarul
Copy link

syarul commented Aug 10, 2016

@calvin how do I use your transport.js?

@pofider
Copy link

pofider commented Jan 30, 2017

The issue disappeared for me after upgrading to the latest winston.

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

9 participants