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'
}
To resolve the "invalid JSON response" error in your Magento 2 PWA setup, follow these steps:
By following these steps, you can address the error and successfully set up your Magento 2 PWA.