-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
RequireJS can't load typeahead.js module #1211
Comments
Same problem here. |
Not sure I agree with the original issue. Isn't a typical practice to define a 'typeahead': './vendor/typeahead.jquery', However, I do agree with @jochenberger . Shouldn't the module register itself upon |
I also have trouble loading typeahead module. |
Yes - I see now that @iMoses is spot-on. Using the In define("typeahead", [ "jquery" ], factory); In my requirejs 'typeahead': './vendor/typeahead.jquery', |
Thanks man! |
+1 to @jochenberger's comment -- I'm rjs-optimising my files so the named module callback never gets called. |
I had the same issue with the ".js" name. Removing it from the code as mentioned by others fixed the problem |
Yeah, what @DrColossos said. |
Yep. Is a real issue. requirejs sees the ".js" and doesn't look in the paths. That's probably more a problem with requirejs than typeahead - many libs have ".js" as a suffix. But still, nice to fix it here if we can. |
Is it possible to "escape" the . (period)? "typeahead.js" or something? |
I can't see any way to do that, have tried a couple of possibles. |
…ding typeahead see: twitter#1211
Thanks. This exchange ended a long search for me! Could this finally be resolved? Having to ask |
👍 to having this resolved soon. The module definition needs to be |
+1 |
Ran into this on my project as well. I'd rather not have the dependency added to the repo, so the quick fix won't suffice. I'd really appreciate it if this were resolved. |
We have a workaround, for the time being, by mapping 'typeahead' to a plugin/proxy file (with the path to the vendor file as argument for the sake of hardcoding things outside the config) in the rjs build file: {
map: {
typeahead: 'src/plugins/typeahead!bower_components/typeahead.js/dist/typeahead.jquery'
}
} And the plugin (to async load/return the actual 'typeahead.js' plugin): define(function () {
return {
load: function (path, parentRequire, onload, config) {
parentRequire([path], function () {
parentRequire(['typeahead.js'], function (ret) {
onload(ret);
});
});
}
};
}); define(['jquery', 'typeahead'], function ($) {
console.log($.fn.typeahead) // typeahead is now a thing.
}); This shim will keep the dependency signature the same until the fix is made, but obviously requires the additional proxy (plugin) file, but if you need to roll this up in prod, the dependency should be included in the build anyway.. |
+1 @peteromano's workaround. |
Here's another workaround, without the need to add a plugin. Just merge this into your require config: paths: {
// define the path as you would with any other AMD module
typeahead: 'bower_components/typeahead.js/dist/typeahead.jquery'
},
shim: {
typeahead: {
deps: [ 'jquery' ],
init: function ($) {
return require.contexts._.registry['typeahead.js'].factory( $ );
}
}
} |
@jpommerening |
@frankleng: Whoopsie, you're right! |
Possible solution is (via build) rewriting almond to expose waiting modules... this would entail the following: _waiting is exposed via almond a la requirejs/almond/pull/66 (https://github.com/jrburke/almond/blob/ae58282adf441f59aadac8f6e6390760333d8fc3/almond.js#L406) Via build; replace
(this is part of your build/gulp/grunt/etc) And then:
Or such like. Best is to fix the module name; solution seems so simple This is a whole cluster f* due to an incorrect module name...? Change the module name? Though as this project seems (?) to be dead should look at fork https://github.com/corejavascript/typeahead.js > same problem has been duplicated. |
Fix from @jpommerening is great but it would be better to strip ou the ".js" part of the module name. |
@charlouze +1 |
Please fix this! Just take the .js out of the module name. I've edited the stanza in my copy to fix the issue. |
+1 |
project is dead and questions may be better placed at https://github.com/corejavascript/typeahead.js.. Posting "+1" does not help in any case.. except to irritate. Read the history; there are a multitude of fixes; max five loc fixes. Extra fix; add grunt/gulp rewrite tasks/rewrite source if it is such a breaking problem. We are programmers? |
@AubreyHewes didn't realise this project was now dead. I've fixed the issue in my local copy but it'd be nice to have it fixed more permanently for version updates etc. Out of interest has it been fixed in the new fork? EDIT: From what I can tell in the source the offending line has been changed. |
@jpommerening, your work around helped, but now I'm getting an error that "Bloodhound is not defined". I'm using the bundle which includes both typeahead and bloodhound. The problem only existed when loaded via require JS. |
The fix mentioned at http://www.bluepage.me/case/4/ works for me. It's a combination of @jpommerening's fix and you must load typeahead and bloodhound JS separately. Don't use the bundle. In require js config: 'typeahead': 'vendors/typeahead.jquery',
'bloodhound': 'vendors/bloodhound' Require js shims: typeahead:{
deps: ['jquery'],
init: function ($) {
return require.s.contexts._.registry['typeahead.js'].factory( $ );
}
},
bloodhound: {
deps: ['jquery'],
exports: 'Bloodhound'
} Finally, include both scripts: require(['typeahead', 'bloodhound'], function(typeahead, Bloodhound){
[Insert typeahead code]]
}); |
RequireJS expects the module name to be delivered without an extension and when an extension is provided it is considered an absolute path, relative to the domain name and not the base URL.
I've just updated
typeahead.js
from version 0.10.5 to 0.11.1 and each time RequireJS will try to load/typeahead.js
and get a 404 since no file exists in this directory (I'm using the typeahead.bundle file).You also cannot create a path for
typeahead.js
, paths in RequireJS must NOT end with a file extension.Can you please rename the module to
typeahead
without the.js
extension?Thanks
The text was updated successfully, but these errors were encountered: