next-contentful-starter icon indicating copy to clipboard operation
next-contentful-starter copied to clipboard

Build fails at CONTENTFUL_ACCESS_TOKEN

Open reedanders opened this issue 5 years ago • 0 comments

Hi there @cassidoo, I just tried to deploy this repo on Netlify, but my build failed with the following error:

4:56:35 PM: > Build error occurred
4:56:35 PM: TypeError: Expected parameter accessToken
4:56:35 PM:     at Module.createClient (/opt/build/repo/node_modules/contentful/dist/contentful.node.js:7563:11)
4:56:35 PM:     at Module.RNiq (/opt/build/repo/.next/server/pages/index.js:151:44)
4:56:35 PM:     at __webpack_require__ (/opt/build/repo/.next/server/pages/index.js:23:31)
4:56:35 PM:     at Object.0 (/opt/build/repo/.next/server/pages/index.js:99:18)
4:56:35 PM:     at __webpack_require__ (/opt/build/repo/.next/server/pages/index.js:23:31)
4:56:35 PM:     at /opt/build/repo/.next/server/pages/index.js:91:18
4:56:35 PM:     at Object.<anonymous> (/opt/build/repo/.next/server/pages/index.js:94:10)
4:56:35 PM:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
4:56:35 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
4:56:35 PM:     at Module.load (internal/modules/cjs/loader.js:986:32) {
4:56:35 PM:   type: 'TypeError'
4:56:35 PM: }

After cloning the repo and running locally, I found the source at utils/contentfulPost.js .

I was able to get the site working by adding the global variables NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN and NEXT_PUBLIC_CONTENTFUL_SPACE_ID within Site settings > Build & deploy > Environment > Environment variables.

Below is my suggested addition to the README with information on how to set these global variables after one-click deploy. Let me know if you approve and I'll create a pull request.

## Add Contentful Access Tokens

You will need to add Contentful access tokens as global variables in Netlify to successfully deploy your site. After creating an account with Contentful, you can add these tokens by navigating to **Site settings > Build & deploy > Environment > Environment variables** and adding the following:

NEXT_PUBLIC_CONTENTFUL_SPACE_ID = [your contentful space id]
NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN = [your contentful access token]

Cheers, Reed

reedanders avatar Apr 15 '21 22:04 reedanders