Showing results for 
Search instead for 
Did you mean: 

Magento 2 PWA setup error

Magento 2 PWA setup error

I got the below error while setup PWA with Magento 2 when I run the yarn build command.
Magento version: 2.4.4
PWA Version: ^0.4.0
PHP version: 8.1
Node Js Version: v16.19.0
Yarn Version: 1.22.19

FetchError: invalid json response body at http://localhost/projectname/graphql reason: Unexpected token < in JSON at position 0
at \projectname\pwa-studio\packages\pwa-buildpack\node_modules\node-fetch\lib\index.js:272:32
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async module.exports (\projectname\pwa-studio\packages\venia-concept\webpack.config.js:61:22) {
type: 'invalid-json'


Re: Magento 2 PWA setup error

To resolve the "invalid JSON response" error in your Magento 2 PWA setup, follow these steps:

  1. Verify the GraphQL endpoint URL in your PWA configuration.
  2. Ensure the GraphQL module is enabled and correctly configured in Magento 2.
  3. Clear the Magento 2 cache using the bin/magento cache:flush command.
  4. Check if the GraphQL response is returning valid JSON data.
  5. Update PWA Studio to the latest version.
  6. Enable debugging in the webpack.config.js file if needed.

By following these steps, you can address the error and successfully set up your Magento 2 PWA.