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

"Error: Cannot find module" when building Electron package #3

Open
audionerd opened this issue Jun 26, 2015 · 1 comment
Open

"Error: Cannot find module" when building Electron package #3

audionerd opened this issue Jun 26, 2015 · 1 comment

Comments

@audionerd
Copy link
Contributor

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
Copy link
Contributor Author

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
      });

      [..]

    });

    [..]

  });

  [..]
});

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

1 participant