Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google-trends-api npm not finding module using browserify

I'm trying to use the google-trends-api npm package with browserify but am getting nowhere. Here's my main.js file

var googleTrends = require('google-trends-api');

var options = {
    geo: 'country name',
    date: 'yyyymm',
    keywords: ['some', 'list', 'of', 'keywords'],
    category: 'some category'
};

googleTrends.apiMethod(options)
.then(function(results){
    console.log("Here are your google trend results!", results);
})
.catch(function(err){
    console.log("there was an error :(", err);
});

And here is my bundle.js

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var googleTrends = require('google-trends-api');

// var options = {
//     geo: 'country name',
//     date: 'yyyymm',
//     keywords: ['some', 'list', 'of', 'keywords'],
//     category: 'some category'
// };

// googleTrends.apiMethod(options)
// .then(function(results){
//     console.log("Here are your google trend results!", results);
// })
// .catch(function(err){
//     console.log("there was an error :(", err);
// });
},{"google-trends-api":2}],2:[function(require,module,exports){
(function (__dirname){
'use strict';

module.exports = require(__dirname + '/lib/utils/');

}).call(this,"/node_modules/google-trends-api")
},{}]},{},[1]);

And here is the error I am getting:

bundle.js:1 Uncaught Error: Cannot find module '/node_modules/google-trends-api/lib/utils/index.js'

Don't know what it could be honestly stumped. I'm on a mac and the message appears in the browser's console.

like image 329
IceTimux Avatar asked Sep 09 '26 12:09

IceTimux


1 Answers

The google-trends-api module contains require calls that include expressions:

module.exports = require(__dirname + '/lib/utils/');

And that expression is causing problems for Browserify, as it is not analysing the require and is not including further dependencies.

However, disregarding that, the google-trends-api module has at least one dependency that is not compatible with usage in the browser, so even if you were to resolve the expressions-in-require-calls issue, it won't work in the browser.

like image 65
cartant Avatar answered Sep 12 '26 02:09

cartant