hydrogen
hydrogen copied to clipboard
[BUG] ShopifyTestProviders contains an undeclared dependancy on faker
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
- Add Storybook to existing Hydrogen 1.5.0 project
- Add a global decorator using ShopifyTestProviders (as per 1.5.0 release notes)
- 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
PR to resolve now merged.
Awaiting release before closing.
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.
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
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
We have a release recently to fix this problem in 2024.4.4
There are more fixed introduced in 2024.4.6