Build a shopify app with node and react failure - Listen for Store Events with Webhooks

Solved
aszalacinski
New Member
2 0 2

So I got to the very last part of the awesome tutorial and am now receiving the following error when implementing the instructions here:

https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/listen-for-store-events-with-w... 

 

When I go to start my server, I get an UnhandledPromiseRejectionWarning error:

 

app_1  | (node:18) UnhandledPromiseRejectionWarning: TypeError: Unexpected MODIFIER at 0, expected END
app_1  |     at mustConsume (/app/node_modules/path-to-regexp/dist/index.js:113:15)
app_1  |     at parse (/app/node_modules/path-to-regexp/dist/index.js:172:9)
app_1  |     at stringToRegexp (/app/node_modules/path-to-regexp/dist/index.js:329:27)
app_1  |     at pathToRegexp (/app/node_modules/path-to-regexp/dist/index.js:403:12)
app_1  |     at new Layer (/app/node_modules/koa-router/lib/layer.js:44:17)
app_1  |     at Router.register (/app/node_modules/koa-router/lib/router.js:561:17)
app_1  |     at Router.<computed> [as get] (/app/node_modules/koa-router/lib/router.js:199:12)
app_1  |     at /app/server.js:70:12
app_1  | (Use `node --trace-warnings ...` to show where the warning was created)
app_1  | (node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
app_1  | (node:18) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The page load returns a 502 Bad Gateway

 

Digging into the issue, it appears the koa-router is making a call to dependency that throws an error but isn't being handled... on April 20th KoaJS team upgraded path-to-regexp from version 1.* to 6.1.0 (release v9.0) and it seems this isn't playing well... downgrading Koa-router to the version used in the tutorial (8.0.8) appears to work fine... posting this so the Shopify team and other would-be partners have a jump off point to troubleshoot. Good luck!

FurnaceX
Shopify Partner
25 2 25

This is an accepted solution.

Thanks for this! I just stumbled on your post and was just having the exact same issue. 

 

I fixed it with a better router path:

Instead of

router.all('*', async (ctx, next) => {

use:

router.all('/(.*)', async (ctx, next) => {

You may also want to use @koa/router instead of koa-router. The later is no longer being updated.

aszalacinski
New Member
2 0 2

@FurnaceX awesome! Thanks for the tip! React/Shopify are new to me so this is EXACTLY why I posted here.

 

What about the ValidateRequest() method from the koa-shopify-auth lib? if you drop that middleware in per the tutorial, does it play nice?

0 Likes
FurnaceX
Shopify Partner
25 2 25

yep, ValidateRequest() works!

0 Likes
SecretCat
New Member
2 0 1

Thank you :D

0 Likes
NagoyaDev
Tourist
9 0 0

You are a king amongst men!

0 Likes
gildniy
New Member
1 0 0

Thank you, this one helped me!

0 Likes