Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug requireJS module defined path/file

I'm new to RequireJS world. I'm getting Load Timeout error for one of the modules, which I've already defined in the main file. I don't see any request in Network tab of Chrome, probably because require has already loaded that file earlier.

I've hooked to onError event of require & I see the error. But the stack doesn't give the exact location/name of the file which tried to load this module. Is there any way to figure out the exact file/linesOfCode ?

Also, is there any way to figure out at runtime all paths that are defined in requireJS, some API like require.getPaths()

like image 358
coding_idiot Avatar asked Jun 28 '14 00:06

coding_idiot


People also ask

Is RequireJS still relevant?

RequireJS has been a hugely influential and important tool in the JavaScript world. It's still used in many solid, well-written projects today.

What is define in RequireJS?

The define() function can be used to load the modules (module can be an object, function, class or a code which is executed after loading a module). You can load different versions of the same module in the same page.

What is a RequireJS module?

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

What is the difference between RequireJS CommonJS and AMD loaders?

The main difference between AMD and CommonJS lies in its support for asynchronous module loading. "The main difference between AMD and CommonJS lies in its support for asynchronous module loading."


1 Answers

requirejs.s.contexts._.config.paths

This will return all paths defined in requirejs. If there are multiple .config calls, it seems to contain all with no duplicates.

like image 148
coding_idiot Avatar answered Sep 25 '22 03:09

coding_idiot