Search code examples
node.jsapiokta

OKTA API - TypeError: fs.existsSync is not a function


I’m following the OKTA API instructions from this link using the code below. However, I’m getting error

TypeError: fs.existsSync is not a function

How to fix this issue? I'm using nodejs v12. wondering if there are updated instructions.

const okta = require('@okta/okta-sdk-nodejs');
const client = new okta.Client({
  orgUrl: 'https://dev-1234.oktapreview.com/',
  token: 'xYzabc'    // Obtained from Developer Dashboard
});

This is the complete error log

applyDefaults
node_modules/@okta/okta-sdk-nodejs/src/config-loader.js:47

  44 | // Apply defaults defined in yaml
  45 | const localYamlPath = path.join(process.cwd(), 'okta.yaml');
  46 | const globalYamlPath = path.join(os.homedir(), '.okta', 'okta.yaml');
> 47 | if (fs.existsSync(globalYamlPath)) {
     | ^  48 |   this.applyYamlFile(globalYamlPath);
  49 | }
  50 | if (fs.existsSync(localYamlPath)) {

Client
node_modules/@okta/okta-sdk-nodejs/src/client.js:35

  32 | super();
  33 | const configLoader = new ConfigLoader();
  34 | const clientConfig = Object.assign({}, config);
> 35 | configLoader.applyDefaults();
     | ^  36 | configLoader.apply({
  37 |   client: clientConfig || {}
  38 | });

./src/App.js/<
src/App.js:6

  3 | 
  4 | const okta = require('@okta/okta-sdk-nodejs');
  5 | 
> 6 | const client = new okta.Client({

Solution

  • The code above is supposed to be used at the server side. It was place wrongly in the client side which cause errors.