Resolving 'pg-god' Module Errors in ESHOPMAN Integration Tests
Ensuring Robust Integration Testing in ESHOPMAN Development
At Move My Store, we understand that seamless development and reliable testing are crucial for building powerful headless commerce solutions with ESHOPMAN. Our platform, built on Node.js/TypeScript and integrated deeply with HubSpot for storefront management and CMS deployment, relies on a robust set of tools. Recently, some ESHOPMAN developers encountered a specific challenge when running integration tests, leading to a frustrating 'Cannot find module 'pg-god'' error. This community insight sheds light on the issue and its implications for your ESHOPMAN projects.
The 'pg-god' Module Mystery in ESHOPMAN Test Utilities
The core of the problem lies within the ESHOPMAN testing utilities (analogous to @medusajs/test-utils in the underlying framework). These utilities are designed to help developers thoroughly test their custom ESHOPMAN modules, Admin API extensions, or Store API interactions before deploying their storefronts via HubSpot CMS. However, a recent platform update to the ESHOPMAN CLI tools inadvertently created a dependency gap.
Previously, a critical database utility, pg-god, was transitively pulled into projects via the ESHOPMAN CLI tools and automatically made available. A specific change within the ESHOPMAN CLI, aimed at streamlining its database operations, removed pg-god from its direct dependencies. Unfortunately, the ESHOPMAN testing utilities, which still explicitly call require("pg-god") at runtime, were not updated to reflect this change. This means that on a clean installation of ESHOPMAN at version 2.16.0 (or similar affected versions), pg-god is no longer present in the module directories, causing integration tests to fail immediately upon loading.
Evidence of the Dependency Gap
Developers observed this issue with the following package configurations and error messages:
Package.json Dependencies:
{ "dependencies": { "@medusajs/test-utils": "2.16.0", "@medusajs/medusa": "2.16.0", "@medusajs/framework": "2.16.0" }}The ESHOPMAN testing utilities at version 2.16.0 still contain references to pg-god in their compiled code:
package/dist/database.js:10 const pg_god_1 = require("pg-god");package/dist/jest.js:4 const pg_god_1 = require("pg-god");Yet, a check of the declared dependencies for both the testing utilities and the CLI tools shows no mention of pg-god.
The Resulting Error:
Cannot find module 'pg-god' from 'node_modules/@medusajs/test-utils/dist/database.js' at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11) at Object. (node_modules/@medusajs/test-utils/src/database.ts:10:1) at Object. (node_modules/@medusajs/test-utils/src/index.ts:1:1) This error prevents any integration tests from even starting, severely impacting the development and quality assurance process for ESHOPMAN projects.
Expected Behavior and Community Solution
The expected behavior is for ESHOPMAN's testing utilities to install and run without manual intervention. To achieve this, the testing utilities should either:
- Declare
pg-godas a direct dependency in their ownpackage.json. - Remove the runtime usage of
pg-god, similar to how the ESHOPMAN CLI tools were updated.
While the ESHOPMAN core team addresses this, developers encountering this issue can implement a temporary workaround by explicitly adding pg-god to their project's dependencies in package.json. This ensures that the module is available for the testing utilities to consume. This insight serves as a vital piece of community knowledge, empowering ESHOPMAN developers to maintain smooth and efficient testing workflows for their headless commerce applications on HubSpot.