facebook / facebook-nodejs-business-sdk

Node.js SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
499 stars 227 forks source link

Cannot read properties of undefined #228

Closed aaronhayes closed 9 months ago

aaronhayes commented 2 years ago

Which SDK version are you using?

13.0.0

What's the issue?

The SDK causes a crash trying to read FacebookAdsApi.getDefaultApi().getAppID(). We do not set the api key via the init method as that was causing us issues with multiple clients. Instead we always pass each object a new API object. e.g. const adAccount = new AdAccount(adAccountId, undefined, undefined, api);

TypeError: Cannot read properties of undefined (reading 'getAppID') at Object.processUncaughtException (/app/node_modules/facebook-nodejs-business-sdk/dist/cjs.js:487:35) at process. (/app/node_modules/facebook-nodejs-business-sdk/dist/cjs.js:464:30)

Steps/Sample code to reproduce the issue

Observed Results:

TypeError: Cannot read properties of undefined (reading 'getAppID') at Object.processUncaughtException (/app/node_modules/facebook-nodejs-business-sdk/dist/cjs.js:487:35) at process. (/app/node_modules/facebook-nodejs-business-sdk/dist/cjs.js:464:30) at process.emit (node:events:539:35) at process.emit (node:domain:475:12) at process._fatalException (node:internal/process/execution:167:25) at processPromiseRejections (node:internal/process/promises:279:13) at processTicksAndRejections (node:internal/process/task_queues:97:32)



#### Expected Results:

  * What did you expect to happen?
  No error to be thrown
banuragaxioned commented 1 year ago

Hi @aaronhayes, did you end up finding out how to work around it?

stcheng commented 1 year ago

@banuragaxioned could you confirm is this still an outstanding issue?

ngobiea commented 7 months ago

I faced the same issuse today after serveral struggle. I solve this issue by using require instead of import. instead of this import adsSdk from 'facebook-nodejs-business-sdk';

use this const adsSdk = require('facebook-nodejs-business-sdk');