首页 > 解决方案 > 'require'未定义VS代码

问题描述

我是 VS Code 的新手。正如标题所示,我试图要求各种 SDK 让我的 JEE 正常运行。当我尝试上线时,控制台会吐出这个错误:

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

我记得在我使用 Android 开发的日子里,我们总是有一个清单文件来要求东西,但我不确定如何在 VS Code 中全局导入/正确调用东西。

这是应该调用一些示例数据的 fbaccess.js 代码(在 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);
});

任何帮助,将不胜感激!

标签: javascriptvisual-studio-code

解决方案


将此添加到头部的 html 中。

 <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>


推荐阅读