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.
This question is related to
javascript
dependency-management
node-modules
For me the issue was I did not have my webpack build mode set to production for the package I was referencing in. Explicitly setting it to "build": "webpack --mode production" fixed the issue.
require
is part of the Asynchronous Module Definition (AMD) API.
A browser implementation can be found via require.js and native support can be found in node.js.
The documentation for the library you are using should tell you what you need to use it, I suspect that it is intended to run under Node.js and not in browsers.
Yes, require is a Node.JS function and doesn't work in client side scripting without certain requirements. If you're getting this error while writing electronJS code, try the following:
In your BrowserWindow declaration, add the following webPreferences field:
i.e, instead of plain mainWindow = new BrowserWindow()
, write
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
});
By default require()
is not a valid function in client side javascript. I recommend you look into require.js as this does extend the client side to provide you with that function.
Source: Stackoverflow.com