Require.js file is not supporting - requirejs

I found the following issue while running my program. Here I send you the firebug console errors and the files which I included in my html page header part.If any one come to know what the issue is kindly tell me the solution.
Firebug console
Error: Module name "request" has not been loaded yet for context: _.
Use require([]) http://requirejs.org/docs/errors.html#notloaded
...c=c[b]});return c}function
C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/err...
my code
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
src="http://requirejs.org/docs/release/2.1.18/minified/require.js"
src="https://raw.githubusercontent.com/natevw/node-chargify/ad91cdec92f41d4045bb6e2189e5a04571576bcc/chargify.js"

you're not loading requirejs in the proper way. Should be like this :
<script data-main="js/your_main_file.js" src="js/require.js"></script>
Have a look at official doc for more info.

Related

How can I get WebStorm to recognize the NodeJS module object?

When I am creating a NodeJS module to be exported, the module object is not recognized. Is there a way to get this module object ot be recognized. I looked under the Settings&Framworks > Node and that appears to be correct. Although I can't seem to keep the "Coding assistance for Node.js" checked (it keeps clearing the 'check')
I looked through IntelliJ's Reference Material Here
I actually may be coding incorrectly as well, perhaps I'm not supposed to hook into this 'exports' object in this manor.
Advice and guidance appreciated.
First this question is very similar to This Question
First I went to the settings (Ctrl-Alt-S) and
'Language & Frameworks' > JavaScript > Libraries
Then I hit the Download button till I found a bunch of node libraries. I figured this was a very 'basic' node object so I used the plain 'node' libary.
Then the #types/node was present for me to enable

requirejs: parse a file and return its dependencies

I have a situation where I need to load (via AJAX in a browser) a file that defines a requirejs module (without executing it) and get back a list of its dependencies.
Ie, given a file that starts with
requirejs(["foo/bar", "foo/baz"], function(bar, baz) {
I'd like the utility to return an array like
["foo/bar", "foo/baz"]
I've found some solutions that will do it using r.js (for example, the ones outlined here: https://groups.google.com/forum/#!msg/requirejs/4C0deWFqpZY/mkZFlw2r_k4J), but nothing to do it in a browser. I can just parse out the require statement myself, but that seems suboptimal. Has anyone come across any solutions for this?

Debug CoffeeScript sources with node-inspector

I'm using CoffeeScript for a while to write Node.js programs. It's ok to debug with node-inspector if I compile the sources with Source Maps.
However, when I try to create a mixed Javascript/CoffeeScript app by using coffee-script/register:
#!/usr/bin/env node
require('coffee-script/register');
require('../src/client');
Then, node-inspector shows the compiled Javascript.
Is there how to see the actual *.coffee sources in node-inspector when I'm not explicity compiling it?
Disclaimer: I am a maintainer of Node Inspector
In order to see the actual *.coffee file in Node Inspector, you need to provide a source-map file describing how to map the transpiled javascript loaded inside Node/V8 runtime to you coffee-script source. Additionally, the filename of the transpiled javascript must be different from the original script name (AFAIK).
This is the trouble with require('coffee-script/register'): it converts the coffee-script source to the javascript source while keeping the same file name. In other words, the runtime (and Node Inspector) see that your *.coffee contain the transpiled javascript, thus it cannot display your coffee script for that very same filename. Also AFAIK, the coffee compiler does not emit any source map in this case.
I see two possible approaches to fix the problem:
Modify loadFile() in coffee-script/register:
emit a source map and save it to a file
pass a different filename to module._compile, e.g. script.coffee.js
Modify coffee-script/register to emit an embedded source map. Fix Chrome DevTools and/or Node Inspector to support embedded source maps.
References:
loadFile() in coffee-script/register
A Node Inspector issue discussing why coffee --nodejs --debug app.coffee does not work now: https://github.com/node-inspector/node-inspector/issues/224
A Node Inspector issue discussing inline source maps: https://github.com/node-inspector/node-inspector/issues/401

How to load multiple named AMD modules defined in a single file?

My understanding is that it shouldn't happen, but it does. What is the most appropriate workaround for these libraries?
Notes:
I figured running these scripts after require.js manually (using a script tag) should work, and indeed it seems like it does. However, the RequireJS documentation explicitly warns that the data-main script is run asynchronously. While require.js should have properly defined the define function needed by the scripts defining multiple named modules, I also assume that without the proper configuration loaded from the data-main script, bad things may happen in a non-deterministic way. Is this correct?
I also fail to see how any combination of the shim, map, bundles and paths configuration properties can help in this case, although I hope I'm missing it.
Clarification on the first note: (My bad, it's really not clear)
What I describe here is simply to manually execute (using an HTML script tag) the script that defines multiple modules after RequireJS and the data-main script. With the knowledge that the latter is run async, my worries should become more obvious (but feel free to ask me to detail some more). The bulk of it is that although it seems like I can require each named module successfully, I'm not sure that the behavior is deterministic (also, it's not pretty, I'd much rather avoid additional script tags and properly load everything asynchronously).
<script src="scripts/require.js" data-main="app/main.js"></script>
<script src="scripts/datajs-1.1.2.js"></script>
Here, datajs-1.1.2.js defines two modules, as described in the link above and copied below:
// AMD support
if (typeof define === 'function' && define.amd) {
define('datajs', datajs);
define('OData', odata);
} ...
What will and will not work depends on the specifics of how the file which defines multiple named modules will be used in an application.
In general, if the order in which modules defined (using named defines) in a single file cannot be determined, then setting paths to map the module names to the file that defines them should prevent problems:
paths: {
'foo': 'path/to/foobar',
'bar': 'path/to/foobar'
}
If foo or bar are required, RequireJS will load the file that defines both (path/to/foobar.js), which is not a problem.
With the details that you've added to the question, I can say this. First, this code:
<script src="scripts/require.js" data-main="app/main.js"></script>
<script src="scripts/datajs-1.1.2.js"></script>
is incorrect. Loading a module that calls define through a <script> tag is generally wrong. (I would say it is always wrong, but there may be some really strange cases where to get incompatible assets to work together you have to do something that would normally be wrong. But this is unusual, and has to be justified.) As you suggested by doing this, you open yourself to timing issues. Sometimes it may work, sometimes it may not.
However, this should prevent any timing issues:
<script>
require = {
paths: {
datajs: 'scripts/datajs-1.1.2',
OData: 'scripts/datajs-1.1.2'
}
};
</script>
<script src="scripts/require.js" data-main="app/main.js"></script>
Whenever anything needs either of the two modules in datajs-1.1.2.js, either because it called require or because it called define with the appropriate module names, the file that defines both modules is going to be loaded.
(Warning: the configuration I show in the example above is an educated guess, which contains enough details to illustrate. It may not work once combined with a configuration already present in app/main.js, and I'm not suggesting that it is the best way to configure RequireJS for your specific application.)
For RequireJS version 2.1.10 and higher, there's also the bundles option, which is nicer to use:
<script>
require = {
bundles: {
"js/datajs-1.1.2": ["datajs", "OData"]
}
};
</script>
<script src="scripts/require.js" data-main="app/main.js"></script>
I suggest reading the documentation on this option to avoid possible misunderstandings as to how it works.

load x3dom using requirejs

I want to load the x3dom js library using requirejs. It's not working and produce the following error: TypeError: x3dom.gfx_webgl is not a function
I load the x3dom library like that:
require(['jquery-ui', 'x3dom'], function($, x3dom){
console.log(x3dom);
$('#test').html("hello");
});
You can see here that the loading of the libs seems to work (it's working for jquery).
I have a jsfiddle that shows the problem: http://jsfiddle.net/ayGR5/2/
If you load the script in the html pane (uncomment <!--<script src="http://www.x3dom.org/download/x3dom.js"></script>--> and comment lines 20-22 in the js pane), it's working.
It was a bug in x3dom. It's fixed now.
https://github.com/x3dom/x3dom/commit/354f1d0f24bf46a045364ac6b1f73f64984c4dc6

Resources