Wednesday, 19 July 2017

dependency management - Javascript require() function giving ReferenceError: require is not defined



Basically, I am using javascript to scrape data from Google Play store using:



1-Request



2-Cheerios



3-QueryString




I used Google Market API from Github which uses require as following:



var request   = require('request');
var cheerio = require('cheerio');
var qs = require('querystring');


But I am getting the following



ReferenceError: require is not defined ...




So, I don't have require in javascript which is either new for me or this is something out of the ordinary.


Answer




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.



IE 6+ .......... compatible ✔

Firefox 2+ ..... compatible ✔
Safari 3.2+ .... compatible ✔
Chrome 3+ ...... compatible ✔
Opera 10+ ...... compatible ✔



http://requirejs.org/docs/download.html



Add this to your project: https://requirejs.org/docs/release/2.3.5/minified/require.js




and take a look at this http://requirejs.org/docs/api.html


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...