2

I am brand new to VS Code. As the title suggests I am trying to require various SDK's for my JEE to run properly. When I try to go live the console spits out this error:

Uncaught ReferenceError: require is not defined
at fbaccess.js:10

I remember from my dev days with Android that we always had a manifest file to require things, but I am not sure how to import/properly call things globally in VS Code.

This is the fbaccess.js code that is supposed to call some sample data (Outputted in node.js:

  /**
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 * @flow
 */

const bizSdk = require('facebook-nodejs-business-sdk');
const AdAccount = bizSdk.AdAccount;
const AdsInsights = bizSdk.AdsInsights;

let access_token = '****';
let ad_account_id = '****';
let app_secret = '****';
let app_id = '****';
const api = bizSdk.FacebookAdsApi.init(access_token);
const account = new AdAccount(ad_account_id);
const showDebugingInfo = true; // Setting this to true shows more debugging info.
if (showDebugingInfo) {
  api.setDebug(true);
}

let ads_insights;
let ads_insights_id;

const logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

const fields = [
  'results',
  'impressions',
  'spend',
  'quality_score_organic',
];
const params = {
  'level' : 'campaign',
  'filtering' : [],
  'breakdowns' : [],
  'time_range' : {'since':'2019-10-09','until':'2019-10-09'},
};
 (new AdAccount(ad_account_id)).getInsights(
  fields,
  params
).then((result) => {
  logApiCallResult('ads_insights api call complete.', result);
  ads_insights_id = result[0].id;
})
.catch((error) => {
  console.log(error);
});

Any help would be appreciated!

Ken White
  • 123,280
  • 14
  • 225
  • 444
Ethan
  • 1,905
  • 2
  • 21
  • 50
  • 4
    VSCode is an editor. It's not a programming language. Please [edit] to include your code, and while making that edit add a tag for the specific language you're using. The editor knows nothing about whether *require* is defined or not. – Ken White Oct 10 '19 at 00:19
  • @KenWhite updated for you – Ethan Oct 10 '19 at 00:22
  • 3
    It's not for me. It's for you, so people who are familiar with the language can help you. And you forgot to add the tag - I got it for you. It helps you get answers more quickly if you provide the information needed to get it in front of people who can help. – Ken White Oct 10 '19 at 00:26
  • @KenWhite thanks, too bad aren't able to lend a helping hand with the answer to the question, but I'm sure your edit suggestions will help me get one. – Ethan Oct 10 '19 at 00:28
  • 3
    A quick google search for the exact error you posted turned this up: https://stackoverflow.com/questions/19059580/client-on-node-uncaught-referenceerror-require-is-not-defined Maybe it would answer your question? It might be smart to google your problems before asking questions in the future. – Alister Oct 10 '19 at 00:31
  • Possible duplicate of [Client on node: Uncaught ReferenceError: require is not defined](https://stackoverflow.com/questions/19059580/client-on-node-uncaught-referenceerror-require-is-not-defined) – hoangdv Oct 10 '19 at 01:06
  • @Alister I suppose that answer handles this question, but I'm left with more knowledge gaps than before. For example, say I wanted to go with Browserify. That's client side, but how do I even include THAT in what is supposed to be a web app? I don't know what the bridge looks like as, in my mind, running an npm command installs it to my local machine only, not other people who would be visiting and using the app on their end – Ethan Oct 10 '19 at 03:03
  • @Ethan Have you got node.js installed? – Sudhakar Ramasamy Oct 10 '19 at 03:27
  • Yes I do, but as a web app shouldn't I be downloading github repositories and/or using a simple script tag to call them? @SudhakarRS – Ethan Oct 10 '19 at 03:29

1 Answers1

2

Add this to the html in the head.

 <script type="text/javascript" src="https://unpkg.com/jquery@3.3.1/dist/jquery.js"></script>
 <script type="text/javascript" src="https://unpkg.com/web3@0.20.5/dist/web3.min.js"></script>