nexe: Error: No such native module ./charset.js

I have read all the previous issue related to ‘No such native module …’ but could not resolve my problem. Hence posting it here for expert eyes. It’s a nodejs express application and I was able to create the exe successfully but when executing, getting this below error

node.js:901
      throw new Error(`No such native module ${id}`);
      ^

Error: No such native module ./charset.js
    at NativeModule.require (node.js:901:13)
    at s (nexe.js:1:176)
    at nexe.js:1:367
    at nexe.js:158393:16
    at Array.forEach (native)
    at Object.__dirname.759 (nexe.js:158391:18)
    at s (nexe.js:1:316)
    at nexe.js:1:367
    at Object.__dirname.3.mime-types (nexe.js:32:18)
    at s (nexe.js:1:316)

Here is the nexe.js code (generated)

function Negotiator(request) {
  if (!(this instanceof Negotiator)) return new Negotiator(request);
  this.request = request;
}

var set = { charset: 'accept-charset',
            encoding: 'accept-encoding',
            language: 'accept-language',
            mediaType: 'accept' };


function capitalize(string){
  return string.charAt(0).toUpperCase() + string.slice(1);
}

Object.keys(set).forEach(function (k) {
  var header = set[k],
      method = require('./'+k+'.js'),
      singular = k,
      plural = k + 's';

  Negotiator.prototype[plural] = function (available) {
    return method(this.request.headers[header], available);
  };

  Negotiator.prototype[singular] = function(available) {
    var set = this[plural](available);
    if (set) return set[0];
  };

  // Keep preferred* methods for legacy compatibility
  Negotiator.prototype['preferred'+capitalize(plural)] = Negotiator.prototype[plural];
  Negotiator.prototype['preferred'+capitalize(singular)] = Negotiator.prototype[singular];
})

Looking at the code, I noticed, code is trying to load some modules ( charset.js for example) from relative path ./charset. So I placed charset.js ( from node_modules/negotiator/lib ) to root directory where .exe was created. But that did not solve the problem. Don’t know what I am missing. Any help would be highly appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 17 (4 by maintainers)

Most upvoted comments

@just4give It’s a browserify issue that’s well known. It’ll be fixed, well, able to be worked around via nexe v2 when I finish that.