cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

Having trouble requiring when.js ~3.x.x with require.js #376

Closed krnlde closed 9 years ago

krnlde commented 9 years ago

I installed when.js via bower. Because of when's new commonJS require();, which was introduced in v3, I am unable to load "when" via require.js.

define(['when'], function (when) {
  // not gonna get here
});

The relative paths ./lib/..., like in var timed = require('./lib/decorators/timed');, are not resolved correctly and the browser fails with a path like this project_root/lib/... instead of project_root/bower_components/when/lib/....

My approach right now is to fall back to v2 which integrates nicely with require.js

Any suggestions on this?

briancavalier commented 9 years ago

Hi @krnlde, could it be that you're configuring RequireJS with a path rather than a package? Here are the instructions for configuring when.js in an AMD environment. If you're using paths, switch to a packages config for when.js and that should do it. If you're already using packages and seeing this problem, then we'll need to dig a bit deeper :)

krnlde commented 9 years ago

Darn, I feel so dumb right now. I indeed included it as a path. This line solved the problem entirely:

requirejs.config({
  packages: [
    { name: 'when', location: '/path/to/when', main: 'when' }
  ]
});

This solution is hard to find. I searched for a solution on google for about one hour now. Searched for "AMD and when.js" or "require.js when.js" but didn't get this result you provided...

Thanks man and sorry for wasting your time.

briancavalier commented 9 years ago

@krnlde No worries at all. Glad that helped.

This solution is hard to find

Hmmm, that's a bummer, and a problem. I wonder how we can make that more visible to google.

krnlde commented 9 years ago

Maybe adding a few more introductional lines containing the keywords AMD, require.js, require, define, when.js right before the instruction itself could help. At least these are the keywords I used to get some help. And adding the requirejs instructions to the README.md would also be helpful, since this was the page I started with checking for the keyword require.