gobblejs / gobble-browserify

Bundle CommonJS modules with gobble and Browserify
4 stars 9 forks source link

Require fails at runtime with "Cannot find module ..' #6

Open ammojamo opened 9 years ago

ammojamo commented 9 years ago

I have a basic sample project here: https://github.com/ammojamo/gobble-browserify-require-broken

The project builds fine, but gobble-browserify generates a bundle where some (but not all) of the paths have been changed to start with '@' (seems to be some magic in cacheDependency). When you attempt to run the javascript in a browser (e.g. open the built index.html), it fails with the error:

Uncaught Error: Cannot find module '@/dependency.js'

Maybe related: the output also contains absolute paths (/Users/myname/etc...) and this is impossible to override in the options because gobble-browserify has options.fullPaths=true hard coded.

P.S. I have tried many build tools in many different languages and Gobble is easily my favourite. Well done! I just love the simplicity of it and confidence with which I can write custom transformations if I need to.

bathos commented 9 years ago

Experiencing the same issue -- imported module is originally in a child /node_modules directory relative to the importer, and there's no error during build, but in the output bundle, the module appears to be mis-addressed with the @ stand-in.

bathos commented 9 years ago

Follow up: this is fixed for me by switching from 0.6.1 to 0.6.0, so it seems this commit is connected to it.

kthompson commented 8 years ago

I have this issue as well. I was able to work around the issue by using the following 'configure' function:

    configure: function(bundle) {
      //Hack to correct the @ symbols and replace with the correct basedir
      var basedir = '';
      bundle.on( 'dep', function ( dep ) {
          if(dep.basedir)
            basedir = dep.basedir;

          for(var child in dep.deps) {
            if(dep.deps[child][0] == '@')    
            {
              dep.deps[child] = basedir + dep.deps[child].substring(1);           
            }
          }
      });
    },

This may have some side effects like preventing the caching mechanism from actually working...