1

I am getting this message: Uncaught Error: Module name "core" has not been loaded yet for context: _. Use require([])

I have looked at How to use jquery ui with requireJS and knockout-sortable? and How do I use jquery ui with requirejs.

I had a shim like this:

// Note that my paths are set so jqueryui points to right place
'jqueryui/core': ['jquery'],
'jqueryui/widget': ['jqueryui/core'],
'jqueryui/position': ['jqueryui/widget'],
'jqueryui/menu': ['jqueryui/position'],
'jqueryui/autocomplete': [
  'jqueryui/core',
  'jqueryui/widget',
  'jqueryui/position',
  'jqueryui/menu'
]

I tried taking away the shim because it's supposed to be AMD. I also tried the export of $ for kicks from the other link. All permutations complain about the line require('./core').

I understand the error because I never required core before this point, but I have the shim. But also the shim probably isn't playing nice with the relative portion.

Update with more info

My actual markup is like this on load:

<script type="text/javascript" src="/assets/node_modules/requirejs/require.js"></script>
<script type="text/javascript" src="/assets/node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/requireconfig.js"></script>
<script type="text/javascript" src="/assets/js/problemfile.js"></script>

The problem file then does:

require(['jqueryui/autocomplete'], function(f) { ... });

However the syntax inside core.js is require('./core').

Since Bower is dead/dying I am using npm to install the dependencies directly, so I believe jquery-ui assumes that I'd be doing require on the server rather than on client using requirejs. I see the bits about browserify, but that won't apply to me I believe since my app is PHP/JS not node on the backend.

As mentioned in comment below, I don't believe this is a dupe question since it has to deal with jquery-ui package specifically, rather than a wrong require call in my own written code.

Community
  • 1
  • 1
Dave Stein
  • 8,653
  • 13
  • 56
  • 104
  • 1
    Why don't you create a custom jQuery ui build rather than loading all components this way... – T J Feb 22 '16 at 06:01
  • As of jQuery UI 1.11, all of the library's source files support using AMD – Omar Sedki Feb 22 '16 at 07:09
  • Possible duplicate of [Dynamic require in RequireJS, getting "Module name has not been loaded yet for context" error?](http://stackoverflow.com/questions/17446844/dynamic-require-in-requirejs-getting-module-name-has-not-been-loaded-yet-for-c) – Louis Feb 22 '16 at 11:34
  • @Louis I don't believe this is a duplicate because the `require('./core`)` is within jquery-ui source whereas the other ticket is about the user's own code – Dave Stein Feb 22 '16 at 16:19

1 Answers1

0

Uncaught Error: Module name "core" has not been loaded yet for context: _. Use require([])

I am not sure if you have loaded it wrong in other places. But according to you error message. It mean you should either call requrie with structure of requireJS insteand commonJS require:

// recommended to avoid confusion with commonJS
requirejs(['./core'],funcion(){
    console.log('core.js is loaded');
});


// alias of requirejs not recommended (can make confusion when reading)
require(['./core'],funcion(){
    console.log('core.js is loaded');
});

P.S. if this answer does not help to solved the issue you will need to provide more details (full config, and how you load core.js)

Linh Pham
  • 3,005
  • 23
  • 34