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.jsstatic_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 herereturnnull}

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',},}

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