hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[BUG] ShopifyTestProviders contains an undeclared dependancy on faker

Open Drew-Garratt opened this issue 2 years ago • 1 comments

Describe the bug As of Hydrogen 1.5.0 a bug has been introduced to the new ShopifyTestProviders HOC including this in a project via the import import {ShopifyTestProviders} from '@shopify/hydrogen/testing';

Will cause builds to throw errors such as the one below. ✘ [ERROR] [plugin vite:dep-pre-bundle] Failed to resolve entry for package "faker". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "faker". The package may have incorrect main/module/exports specified in its package.json.

This is because /packages/hydrogen/src/utilities/tests/price.ts includes faker as a dependency in order to create a randomised amount value for the getPrice function.

As this dependency is not declared in /packages/hydrogen/package.json this creates an undeclared dep.

To Reproduce

  1. Add Storybook to existing Hydrogen 1.5.0 project
  2. Add a global decorator using ShopifyTestProviders (as per 1.5.0 release notes)
  3. Run Storybook and attempt to view a wrapped component

Expected behaviour Either, faker should be declared as a dependency or the dependency should be removed from /packages/hydrogen/src/utilities/tests/price.ts

I am raising a PR that suggests the latter as a fix as I do not believe a randomised fallback value for the price is necessary for testing.

  • Hydrogen version 1.5.0

Drew-Garratt avatar Oct 11 '22 13:10 Drew-Garratt

PR to resolve now merged.

Awaiting release before closing.

Drew-Garratt avatar Oct 14 '22 06:10 Drew-Garratt

Upon further inspection, the value for consent.checkoutDomain is set through the env variable PUBLIC_CHECKOUT_DOMAIN (line 75 of root.jsx and line 22 of entry.server.jsx)

But this PUBLIC_CHECKOUT_DOMAIN env is actually not being pulled when I run npx shopify hydrogen env pull. When I add the env manually, it works as expected.

Quick question - What should the value of PUBLIC_CHECKOUT_DOMAIN be? I don't see it anywhere in the docs.

shreyas707 avatar Jun 11 '24 17:06 shreyas707

Update: Same issue after deploying to Oxygen.

I tried adding PUBLIC_CHECKOUT_DOMAIN env in Hydrogen App's Storefront Settings manually and deploying again, but still getting 500 Invariant Failed error

shreyas707 avatar Jun 11 '24 18:06 shreyas707

Update 2: Found the issue. In package.json, the shopify cli version is set exactly to 3.60.0. Seems like this version of cli is not setting PUBLIC_CHECKOUT_DOMAIN env.

I changed it to ^3.60.0 so that it pulls the most recent minor version and it started working again! Works fine on Oxygen as well. At the time of writing this, it pulled 3.61.2

shreyas707 avatar Jun 11 '24 18:06 shreyas707

We have a release recently to fix this problem in 2024.4.4

wizardlyhel avatar Jun 14 '24 16:06 wizardlyhel

There are more fixed introduced in 2024.4.6

wizardlyhel avatar Jun 17 '24 16:06 wizardlyhel