adamschwartz / log

Console.log with style.
https://adamschwartz.co/log
MIT License
3.01k stars 140 forks source link

Undefined in requirejs #34

Closed wenerme closed 9 years ago

wenerme commented 9 years ago

main.js

  //the require library is configuring paths
  require.config({
    baseUrl: "../assets",
    paths: {
      //tries to load jQuery from Google's CDN first and falls back
      //to load locally
      log: ['log/log'],
      ractive: ['//cdn.ractivejs.org/latest/ractive'],
      rv: ["rv/rv"],

      jquery: ['//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min', 'jquery/jquery'],
      bootstrap: ['//netdna.bootstrapcdn.com/bootstrap/3.3.3/js/bootstrap.min', 'bootstrap/bootstrap'],
      moment: ['moment/moment']
    },
    shim: {
      'bootstrap': {
        deps: ['jquery']
      }
    },
    //how long the it tries to load a script before giving up, the default is 7
    waitSeconds: 10
  });
//requiring the scripts in the first argument and then passing the library namespaces into a callback
//you should be able to console log all of the callback arguments
  require(['jquery', 'moment', 'log', 'ractive', 'rv'],
    function ($, moment, log,Ractive, rv)
    {
      console.log(arguments, window.log);
      log("Log by log");
    });
})(require);

bower.json

{

  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "app/assets",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "bootstrap": "~3.3.4",
    "jquery": "~2.1.3",
    "fontawesome": "~4.3.0",
    "moment": "~2.9.0",
    "requirejs": "~2.1.16",
    "rv": "~0.1.8",
    "log": "~0.1.5"
  }
}

.bowerrc

{
    "directory": "app/assets"
}
ghost commented 9 years ago

@wenerme I'm having the same problem, were you able to figure this out?

ghost commented 9 years ago

I figured it out. The AMD definition is incorrect at log.coffee:110:

  define exportedLog

should be

  define -> exportedLog

@adamschwartz I can make a pull request with this fix if desired, or you can do it since it's so small.

adamschwartz commented 9 years ago

Thanks @wenerme & @dav- for reporting this.

Interestingly enough, it looks like this was fixed with #32 in the JS, but not the original Coffeescript. Are we sure that this is now correct?

Let’s also loop in @alessioalex, the original author of the AMD stuff (#30), and @rodneyrehm, the author of the JS fix in (#32), for some extra eyes.

ghost commented 9 years ago

@adamschwartz I found that just before you commented. It's interesting that it's fixed in the JS, because the package I got from Bower seemed to have the unfixed JS.

rodneyrehm commented 9 years ago

32 only fixed the compile target, not the compiled source. so any time someone compiled the CoffeeScript, the error would reappear. I have no Idea how I only fixed the JS, but not the CS. Shame on me :/

adamschwartz commented 9 years ago

Np @rodneyrehm :)

Alllright. https://github.com/adamschwartz/log/commit/86a79c73a557b23fbc2419795717e5c0ab899ad9 and https://github.com/adamschwartz/log/commit/fadf2433211f329890093c83ee2ee637f7e742fb should bring us home.

Thx all!