jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

Issue with require.js since 4.4.1 #234

Closed xi closed 8 years ago

xi commented 8 years ago

Loading angular-cache with require.js fails for me since 4.4.1. If I revert 8e852310480bddfb796848b89bdc6c4ade5d1f1b, it works fine. Tested with require 2.1.22 and 2.2.0.

jmdobry commented 8 years ago

I just did this to test:

$ git clone git@github.com:jmdobry/angular-cache.git
$ cd angular-cache
$ npm install -g bower requirejs
$ bower install
$ cd build_examples/r.js
$ r.js -o require.config.js
$ open index.html

and everything worked. Can you explain what you did differently so I can reproduce your error? Maybe provide more information like, what exactly your error is?

xi commented 8 years ago

Thanks for the feedback. I will investigate this further. However, that won't be possible for the next two weeks. I will come back to you after that.

xi commented 8 years ago

Sorry for the long wait. I found somewhat minimal test case:

require.config({
  paths: {
    angular: '../../bower_components/angular/angular',
    angularCache: '../../dist/angular-cache',
  },
  shim: {
    'angular': {
      exports: 'angular'
    }
  }
});

Note the camelCase in angularCache (app.js was changed accordingly). If I change to angular-cache, everything works fine. This may not be a major issue, but still a bug.

jmdobry commented 8 years ago

How is it a bug? The key you use in the paths object should match the name of the package, i.e. angular-cache.

require.config({
  paths: {
    angular: '../../bower_components/angular/angular',
    'angular-cache': '../../dist/angular-cache',
  },
  shim: {
    'angular': {
      exports: 'angular'
    }
  }
});
xi commented 8 years ago

As far as I know the keys in the paths object are completely arbitrary. In our project, we have the convention to use camelCase module names, so we naturally mapped angular-cache to angularCache.

The require.js docs seems to agree with that:

You can explicitly name modules yourself, but it makes the modules less portable

As I said earlier, this is not a huge issue though. I just thought I should report it in case other people have the same issue.

jmdobry commented 8 years ago

Sounds good.