electron-jsx-babel-boilerplate icon indicating copy to clipboard operation
electron-jsx-babel-boilerplate copied to clipboard

"Error: Cannot find module" when building Electron package

Open audionerd opened this issue 9 years ago • 1 comments

bundle:dependencies uses the basename of the main file when determining location and standalone name. But some modules keep their main JavaScript in a subfolder, e.g.: async has async/lib/async.js, js-csp has js-csp/src/csp.js.

audionerd avatar Jun 26 '15 20:06 audionerd

I fixed the issue locally by finding the actual main of the file, and using the basename only for the standalone, e.g:

gulp.task('bundle:dependencies', function () {

  [..]

  // create a list of dependencies' main files
  var modules = dependencies.map(function (dep) {
    var packageJson = require(dep + '/package.json');
    var main;
    if(!packageJson.main) {
      main = ['index.js'];
    } else if(Array.isArray(packageJson.main)) {
      main = packageJson.main;
    } else {
      main = [packageJson.main];
    }
    return {name: dep, main: main.map(function (it) { return it })}; // skip basename here
  });


  [..]

  // create bundle file and minify for each main files
  modules.forEach(function (it) {
    it.main.forEach(function (entry) {
      var b = browserify('node_modules/' + it.name + '/' + entry, {
        detectGlobal: false,
        standalone: path.basename(it.name) // basename here
      });

      [..]

    });

    [..]

  });

  [..]
});

audionerd avatar Jun 26 '15 20:06 audionerd