Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

error "gatsby-source-github-api" threw an error while running the sourceNodes lifecycle: token is undefined

I am new to Gatsby and just tried a GH Actions workflow for my site today. I see this error at the build stage:

error "gatsby-source-github-api" threw an error while running the sourceNodes lifecycle: token is undefined

I am using this to pull all repos on my Github into the site.

What I have tried so far:

  • Checked the Github personal access token
  • the build is working locally

Versions:

"gatsby-source-github-api": "^0.2.1" "gatsby": "^2.26.1"

This is my node.js.yml GH Actions workflow file:

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [13.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run build

PS: I have used a .env file to hold the value of the token that the plugin 'gatsby-source-github-api' requires. And it is in my .gitignore file. So which means it is not sent to GH and hence can't find it?

question from:https://stackoverflow.com/questions/65876158/error-gatsby-source-github-api-threw-an-error-while-running-the-sourcenodes-li

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So that was it -- the .env file which wasn't being pushed to Github. So I needed to make the token available to the GH Action build somehow. I tried the action SpicyPizza/create-envfile@v1. It isn't supported by Github but seemed to do the job. It creates a .env file at build with the keys you provide it.

You could also create a .env file manually. See thread.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...