typeahead.js: RequireJS can't load typeahead.js module

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

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 2
  • Comments: 30

Commits related to this issue

Most upvoted comments

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( $ );
        }
    }
}

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]]
});

@jpommerening should be return require.s.contexts._.registry['typeahead.js'].factory( $ );

👍 to having this resolved soon. The module definition needs to be typeahead, without extension, like any other AMD module…