magento2-connector icon indicating copy to clipboard operation
magento2-connector copied to clipboard

error connecting magento locally

Open emehran opened this issue 5 years ago • 19 comments

Hi guys, First of all thanks for the great work!

I'm trying to test it locally. I've followed the steps about using magento connector. I've one local magento setup on magento.test URL, and set up .env file like LEGACY_BACKEND_DOMAIN=magento.test LEGACY_BACKEND_HOST_HEADER=magento.test M2_CONFIG_HOST=http://magento.test

but when I npm start, it crashes with invalid json error which is actually a 500 internal error for getting the app data.

Did I miss any steps? thanks

emehran avatar Sep 24 '20 08:09 emehran

Hi @emehran. What's your upstream (i.e. M2_CONFIG_HOST)? Could you provide more of error data you're getting? Thanks!

satelllte avatar Sep 30 '20 14:09 satelllte

I'm also not able to get the connector working with the initial installation of react-storefront

 1 of 1 unhandled error
Server Error
FetchError: invalid json response body at http://localhost:3000/api/s/117?_includeAppData=1 reason: Unexpected token I in JSON at position 0

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
pages/_app.js (54:16) @ async Function.MyApp.getInitialProps

  52 | 
  53 |   if (Component.getInitialProps) {
> 54 |     pageProps = await Component.getInitialProps(ctx)
     |                ^
  55 |   }
  56 | 
  57 |   return { pageProps }
Show collapsed frames

when localhost:3000/api?_includeAppData=1 is being requested, the following is put console:

TypeError: Object(...) is not a function
    at eval (webpack-internal:///./pages/api/index.js:6:89)
    at apiResolver (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/api-utils.js:8:7)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async DevServer.handleApiRequest (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/next-server.js:47:397)
    at async Object.fn (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/next-server.js:39:218)
    at async Router.execute (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/router.js:23:67)
    at async DevServer.run (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/next-server.js:49:494)
    at async DevServer.handleRequest (/Users/mcjambi/repos/react-storefront-test/node_modules/next/dist/next-server/server/next-server.js:17:101)

umizoomi avatar Oct 05 '20 14:10 umizoomi

I'm having the same problem, with the following terminal output:

TypeError: Object(...) is not a function at eval (webpack-internal:///./pages/api/index.js:6:89) at apiResolver (/.../node_modules/next/dist/next-server/server/api-utils.js:8:7) at process.internalTickCallback (internal/process/next_tick.js:77:7) { FetchError: invalid json response body at http://localhost:3000/api?_includeAppData=1 reason: Unexpected token I in JSON at position 0 at /.../node_modules/next/dist/compiled/node-fetch/index.js:1:133652 at process.internalTickCallback (internal/process/next_tick.js:77:7) message: 'invalid json response body at http://localhost:3000/api?_includeAppData=1 reason: Unexpected token I in JSON at position 0', type: 'invalid-json' }

I'm running M2 locally on Docker and have configured my dotenv file with M2_CONFIG_HOST.

Linusjonss avatar Oct 06 '20 09:10 Linusjonss

I can confirm, the pristine installation, following the guide, will result in error.

http://localhost:3000/api?_includeAppData=1

Results in: Internal Server Error

Maybe it's something missing from the documentation?

ffrappo avatar Oct 08 '20 14:10 ffrappo

Could this be related to #26 ?

You can try to check Magento 2 logs and see if it makes it there. This was how I discovered the source of my issue with the default install.

You can run: tail -f var/log/exception.log

Reload the page, and you will see the error, if it is happening in Magento.

acrois avatar Oct 16 '20 11:10 acrois

Hi,

I have the same error, just installing the package results in this error. Even before changing the connector in next.config.js

Installing version 1.0.2 of the connector worked for me npm install [email protected]

Best, Vincent

vperrin avatar Oct 18 '20 11:10 vperrin

None of these solutions seems to work for me. Is there a minimum required Magento 2 version?

Linusjonss avatar Oct 20 '20 08:10 Linusjonss

Running into the same issue on my end. Request isn't showing up in var/log/exception.log or any other magento logs. Downgrading from "react-storefront-magento2-connector": "^1.0.3" to "react-storefront-magento2-connector": "^1.0.2" also didn't make a difference. Any ideas on other things I could try to resolve this?

I'm getting the following errors:

Server Error
FetchError: invalid json response body at http://localhost:2020/api?_includeAppData=1 reason: Unexpected token I in JSON at position 0

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
pages/_app.js (86:16) @ async Function.MyApp.getInitialProps

  84 | 
  85 |   if (Component.getInitialProps) {
> 86 |     pageProps = await Component.getInitialProps(ctx)
     |                ^
  87 |   }
  88 | 
  89 |   return { pageProps }
FetchError: request to https://magento.redacted.net/graphql failed, reason: connect ETIMEDOUT XXX.XX.XXX.XXX:443
    at ClientRequest.<anonymous> (/Users/react-storefront-example/src/node_modules/next/dist/compiled/node-fetch/index.js:1:66404)
    at ClientRequest.emit (node:events:327:20)
    at TLSSocket.socketErrorListener (node:_http_client:478:9)
    at TLSSocket.emit (node:events:327:20)
    at emitErrorNT (node:internal/streams/destroy:194:8)
    at emitErrorCloseNT (node:internal/streams/destroy:159:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT'
}

My .env file looks like this:

LEGACY_BACKEND_DOMAIN=magento.redacted.net
LEGACY_BACKEND_HOST_HEADER=magento.redacted.net
M2_CONFIG_HOST=http://magento.redacted.net

MatousKundrik avatar Nov 08 '20 19:11 MatousKundrik

I have the same issue. Any solution?

Rickywils avatar Nov 11 '20 18:11 Rickywils

vperrin's solution worked for me, in a sense. I can now launch the landing page with the products loaded, but navigating off that page results in errors. :

"Hi,

I have the same error, just installing the package results in this error. Even before changing the connector in next.config.js

Installing version 1.0.2 of the connector worked for me npm install [email protected]

Best, Vincent"

keithmacinnis avatar Nov 12 '20 23:11 keithmacinnis

Vperrin's solution right but in this case, we lose the new features Main features: PLP, PDP, and Cart page at the last version

versions 1.0.3 and 1.0.4 not working but the reason?

robertbaum avatar Mar 02 '21 14:03 robertbaum

Installing version 1.0.2 worked for me.

spacegauch0 avatar Apr 14 '21 09:04 spacegauch0

Same issue here. I downgraded to 1.0.2 and it's working now but the new features have been lost.

pablolgarcia avatar May 06 '21 13:05 pablolgarcia

@pablolgarcia I've tried multiple ways to reach out to the company and they are unresponsive. I have made some patches to the code to work past some of the issues and limitations in the code but still not able to have everything fully function. We need the author's help or more time spent on the community side (you and I) on fixing it.

acrois avatar May 06 '21 22:05 acrois

I have the same issue. Is there any other solution to solve this? Please help me.

Konlll avatar Feb 17 '22 19:02 Konlll

Hey authors! Any words? With this error nobody can use this connector.

Konlll avatar Feb 18 '22 09:02 Konlll

the old 1.0.2 connector works for me but it has its own issues. I'm still looking for solutions one thing they mentioned in the doc is to directly use the API in pages/api folder, ill see if it thing works.

SankalpChari52 avatar Feb 21 '22 05:02 SankalpChari52

I have the same issue Node v16.14 Mac Monterey 12

even installing 1.0.2 doesn't help for me

timothyk0908 avatar Mar 17 '22 13:03 timothyk0908

I got the page to show items with this magento connector So i'm using 1.0.2 for now The way i can see some products on the page is by 1 - clicking on one of the categories 2 - page won't really display any products 3 - manually refresh the page (you should see products and filters)

rbuenavida avatar Nov 08 '22 19:11 rbuenavida