WP-API / node-wpapi

An isomorphic JavaScript client for the WordPress REST API
http://wp-api.org/node-wpapi/
MIT License
1.68k stars 190 forks source link

Issue using wp-api with next.js/now v2 serverless #431

Open cordial opened 5 years ago

cordial commented 5 years ago

Hi,

Everything is fine using wp-api locally and for development, but when i try and build for production (or if i try to deploy to now v2), I get the following issue when i run 'yarn build' (which in turn runs 'next build' -

"TypeError: require is not a function at Object.+nUH (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:605:14) at webpack_require (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:23:31) at Object.ubcj (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:34974:20) at webpack_require (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:23:31) at Object.jz7c (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:28717:20) at webpack_require (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:23:31) at Object.E58G (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:5780:15) at webpack_require (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:23:31) at Object.+m56 (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:166:23) at __webpack_require__ (/Users/cordial/newman/headless-wp-starter/frontend/.next/serverless/pages/page/design-print.js:23:31) error Command failed with exit code 1."

I'm using - "wpapi": "^1.2.1"

If I comment out wpapi, the error goes away.

There is a thread about this on the next spectrum chat, but to no conclusion - https://spectrum.chat/zeit/now/trying-to-make-wordpress-work~c623bcf6-3853-4f79-a598-2b410501538b

Not really sure if this is something you can help with, or if I need to keep trying on the now/next.js side..

cordial commented 5 years ago

Sorry, I should have mentioned that this is deploying to now v2 with a 'target' : 'serverless' setting in the next.config.js file.

vdiaza commented 4 years ago

I am having the same problem but using nuxt instead! have you found any solution @cordial ?

cordial commented 4 years ago

hey, looking at my now.sh account, I didn't deploy using now.sh in the end. I ended up using Heroku to get round the problem, the same project deployed fine on there.