cancel
Showing results for 
Search instead for 
Did you mean: 

PWA studio build error - Fetch error -

PWA studio build error - Fetch error -

Config:

"magento/product-community-edition": "2.3.3"
"PWA Studio": 4.0.0

Magento Core and PWA studio are in separate servers.

when running yarn build in PWA studio folder, i face this issue :

yarn run v1.22.10
$ yarn run build:prod
$ yarn run clean && yarn run load-env && webpack --no-progress --env.mode production
$ rimraf dist
$ node ../pwa-buildpack/bin/buildpack load-env --core-dev-mode .
{ FetchError: invalid json response body at https://********/graphql reason: Unexpected token < in JSON at position 0
    at /home/********/packages/pwa-buildpack/node_modules/node-fetch/lib/index.js:241:32
    at process._tickCallback (internal/process/next_tick.js:68:7)
  message:
   'invalid json response body at https://********/graphql reason: Unexpected token < in JSON at position 0',
  type: 'invalid-json' }
FetchError: invalid json response body at https://********/graphql reason: Unexpected token < in JSON at position 0
    at /home/********d/packages/pwa-buildpack/node_modules/node-fetch/lib/index.js:241:32
    at process._tickCallback (internal/process/next_tick.js:68:7)

after some debugging, i found out that the error happens during webpack bundling, at this line :

const mediaUrl = await getMediaURL();

so i decided to test if i can do a request to my backend from PWA studio server, and this command worked successfully :

curl -H 'Content-Type: application/json' -X POST -d '{"query": "query {storeConfig{ id secure_base_media_url} }"}' https://********/graphql

the query worked also in Altair GraphQL client.


last thing to mention, the build was successful when using the default backend as MAGENTO_BACKEND_URL env.

i tried to list all my debugging step, any help would be appreciated .