Skip to content

GraphQL helper: false "axios not installed" error due to require() in ESM context (CodeceptJS 4.0.8) #5654

Description

@mmaaxi

What are you trying to achieve?

Run npx codeceptjs check with the GraphQL helper configured.

What do you get instead?

CodeceptJS throws an error claiming axios is not installed, even though it is present in node_modules.

Error: Required modules are not installed.

RUN: [sudo] npm install -g axios
    at checkHelperRequirements (.../node_modules/codeceptjs/lib/container.js:434:13)
    at .../node_modules/codeceptjs/lib/container.js:370:15

Root cause: GraphQL.js uses require('axios') inside _checkRequirements(), but since CodeceptJS 4 is ESM, require is not defined. This causes the catch block to always trigger and incorrectly report axios as missing.

// node_modules/codeceptjs/lib/helper/GraphQL.js
static _checkRequirements() {
  try {
    require('axios')  // ❌ require is not defined in ESM context
  } catch (e) {
    return ['axios'] // always returns this, even when axios IS installed
  }
}

Suggested fix:

static _checkRequirements() {
  // axios is already imported at the top of this ESM file,
  // so no runtime check is needed here
  return null
}

Details

  • CodeceptJS version: 4.0.8
  • NodeJS Version: v20.20.2
  • Operating System: Windows 11 Pro
  • puppeteer || webdriverio || protractor || testcafe version (if related): Playwright 1.39.0
  • Configuration file:
helpers: {
  GraphQL: {
    endpoint: 'https://rickandmortyapi.com/graphql',
  },
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions