Skip to content

ReferenceError: require is not defined #246

Description

@ADNolan

return new (require(moduleName).Agent)({ keepAlive: true });

ReferenceError: require is not defined
    at createKeepAliveAgent (file:///Users/nolan/Documents/my-app/node_modules/@contentstack/core/dist/esm/src/lib/contentstack-core.js:11:5)
    at httpClient (file:///Users/nolan/Documents/my-app/node_modules/@contentstack/core/dist/esm/src/lib/contentstack-core.js:20:20)
    at Module.stack (file:///Users/nolan/Documents/my-app/node_modules/@contentstack/delivery-sdk/dist/modern/stack/contentstack.js:61:18)

The only way I can solve this is shimming app start up before contentstack initialization happens.

import {createRequire} from 'module';

if (typeof globalThis.require === 'undefined') {
  globalThis.require = createRequire(import.meta.url);
}

Version Info:

  • @contentstack/delivery-sdk@5.5.1
  • @contentstack/core@1.5.0
  • @contentstack/utils@1.9.1
  • Node 22.22.0 and Node 24.19.0

Not that it might be as relevant, this also happens in the @contentstack/delivery-sdk@4.12.1.

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