1
I am making an application that will consume some Twitter data. I am using the library recommended by API developers, as my application is only to consume API I use only Javascript and jQuery, so I use the library Twitterjsclient.
In this library, right at the beginning of the archive /TwitterJSClient/lib/Twitter.js
has the following code:
var OAuth = require('oauth').OAuth;
var qs = require('qs');
After analyzing its folder and file structure, I saw that it has some named directories of oauth
and qs
.
When attaching this project to mine, at first it does not work because these functions do not belong to Javascript or jQuery, ie, Undefined.
What little I know about Requirejs, is that it carries files into another, enabling the use of it. However, even after using Requirejs (version ~2.1.14) I installed via Bower (bower install requirejs
) the project does not work as it should.
The Error that gives is the following:
Uncaught Error: Module name "oauth" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
I changed the project code to:
var OAuth = require(['oauth']).OAuth;
var qs = require(['qs']);
And the result changes to:
GET http://192.168.0.22:9000/oauth.js 404 (Not Found)
Uncaught Error: Script error for: oauth
http://requirejs.org/docs/errors.html#scripterror
GET http://192.168.0.22:9000/qs.js 404 (Not Found)
Uncaught Error: Script error for: qs
http://requirejs.org/docs/errors.html#scripterror
Directory and file structure (partial):
Project/
app/
images/
scripts/
TwitterJSClient/
lib/
Twitter.js
node_modules/
.bin/
jasmine-node/
oauth/
examples/
lib/
_ultils.js
oauth.js
oauth2.js
sha1.js
tests/
index.js
qs/
test/
index.js
test/
index.js
main.js
styles/
index.html
bower_components/
requirejs/
require.js
node_modules/
test/
Can someone show me a way to use the Twitterjsclient in my project?
You can put your folder structure and your
oauth.js
here?– Sergio
I put it on, but I don’t know how to use Markdown. If you can tidy up!
– Phellipe Lins
Have you tried giving the complete path in require? the error you gave points to this:
http://192.168.0.22:9000/oauth.js 404 (Not Found)
– Sergio
Turns out I don’t know how to use require well. I don’t really know if it’s trying to get the oauth.js file or the whole oauth directory. And as I use Yeaoman the root path of development diverges from the root path of production. I think it’s not cool to put complete path.
– Phellipe Lins
'Cause require assumes the file is
.js
and then you don’t need to put the file extension. Test the full path in the browser to see if you find the file... typehttp://192.168.0.22:9000/lib/oauth.js
– Sergio
I changed the directory to "scripts/Twitterjsclient/node_modules/oauth/lib/oauth" and it worked. However, within this file there are other require for other files and also an undefined function called EXPORTS.
– Phellipe Lins
I noticed that require I installed via Bower always searches files from path "app/". I do not need to make any change on that, if that is possible?
– Phellipe Lins