javascript - RequireJS not loading module before use its variables -
i'm getting undefined error new library plugged in requirejs
. know undefined error related 'wnumb'
module not loading before used. if load 'wnumb'
module in config.js
this: require(['main', 'wnumb']);
works.
// conifg.js require.config({ paths: { 'main': 'main', 'socketio': './libs/socket.io/socket.io', 'plotly': './libs/plotly/plotly-latest.min', 'renderdatatoplotly': './scripts/renderdatatoplotly', 'nouislider': './libs/nouislider.8.5.1/nouislider.min', 'wnumb': './libs/wnumb-1.0.2/wnumb', 'sliders': './scripts/sliders', 'makeplotlywindowresponsive': './scripts/makeplotlywindowresponsive' } }); require(['main']);
// main.js define([ 'socketio', 'sliders', //---------------------------------------------> note: sliders.js loading here 'makeplotlywindowresponsive', 'renderdatatoplotly' ], function(io, sliders, makeplotlywindowresponsive, renderdatatoplotly) { // } );
// sliders.js define(['nouislider', 'wnumb'], function(nouislider, wnumb) { console.log(wnumb); // ---------------------------------------------------> undefined });
question: why happening? should not 'wnumb'
have been loaded time console.log(wnumb);
executes?
thank you
indeed, when have trouble library using requirejs, should check how exports itself. documentation tell compatible with. otherwise, have read source code. use wnumb 1.0.2 requirejs have have behave proper amd module must use shim:
shim: { wnumb: { exports: "wnumb", }, }
this give module value of global variable wnumb
(which same window.wnumb
). how libraries don't know amd export in global space work requirejs.
however, if can upgrade wnumb 1.0.4 better because version has introduced proper code make wnumb
proper amd module: calls define
when detects there amd loader available. don't need shim
then.
Comments
Post a Comment