无法在 netlify 上部署 gatsby wordpress 站点

Fails to deploy gatsby wordpress site on netlify

需要帮助请找出下面的错误。 我尝试在 netlify 上部署我的 gatsby Wordpress 网站,但出现此错误?

7:24:55 PM: failed Building static HTML for pages - 0.556s
7:24:55 PM: error Building static HTML failed for path "/search/"
7:24:55 PM: 
7:24:55 PM:    8 |
7:24:55 PM:    9 | const SearchPage = ({ location }) => {
7:24:55 PM: > 10 |   const { userQuery, searchQuery } = location.state
7:24:55 PM:      |           ^
7:24:55 PM:   11 |
7:24:55 PM:   12 |   const [searchData, setSearchData] = useState([])
7:24:55 PM:   13 |   const [currentPage, setCurrentPage] = useState(1)
7:24:55 PM: 
7:24:55 PM:   WebpackError: TypeError: Cannot destructure property 'userQuery' of 'location.  state' as it is undefined.
7:24:55 PM:   
7:24:55 PM:   - search.js:10 
7:24:55 PM:     mugentage/src/pages/search.js:10:11
7:24:55 PM:   
7:24:55 PM:   - extends.js:6 
7:24:55 PM:     [mugentage]/[@babel]/runtime/helpers/extends.js:6:1
7:24:55 PM:   
7:24:55 PM:   - extends.js:9 
7:24:55 PM:     [mugentage]/[@babel]/runtime/helpers/extends.js:9:1
7:24:55 PM:   
7:24:55 PM:   - extends.js:14 
7:24:55 PM:     [mugentage]/[@babel]/runtime/helpers/extends.js:14:1
7:24:55 PM:   
7:24:55 PM:   - static-entry.js:263 
7:24:55 PM:     mugentage/.cache/static-entry.js:263:20
7:24:55 PM:   
7:24:55 PM: 
7:24:55 PM: ​
7:24:55 PM: ────────────────────────────────────────────────────────────────
7:24:55 PM:   "build.command" failed                                        
7:24:55 PM: ────────────────────────────────────────────────────────────────
7:24:55 PM: ​
7:24:55 PM:   Error message
7:24:55 PM:   Command failed with exit code 1: npm run build
7:24:55 PM: ​
7:24:55 PM:   Error location
7:24:55 PM:   In Build command from Netlify app:
7:24:55 PM:   npm run build
7:24:55 PM: ​
7:24:55 PM:   Resolved config
7:24:55 PM:   build:
7:24:55 PM:     command: npm run build
7:24:55 PM:     commandOrigin: ui
7:24:55 PM:     environment:
7:24:55 PM:       - REACT_APP_DISQUS_ID
7:24:55 PM:       - REACT_APP_INSTAGRAM_TOKEN
7:24:55 PM:     publish: /opt/build/repo/public
7:24:55 PM:     publishOrigin: ui
7:24:55 PM:   plugins:
7:24:55 PM:     - inputs: {}
7:24:55 PM:       origin: ui
7:24:55 PM:       package: '@netlify/plugin-gatsby'

根据错误:

7:24:55 PM:    9 | const SearchPage = ({ location }) => {
7:24:55 PM: > 10 |   const { userQuery, searchQuery } = location.state

您的 SearchPage 正在解构 location,而由于某种原因,它可能是 undefinednull,破坏了以下解构。

要绕过它,请将默认值添加到 location 属性,就像:

const SearchPage = ({ location={} }) => {

甚至 location={state:{}}.

正如我在评论中所说,您的代码也不会在本地运行,因此首先需要在推送或部署之前修复它。在本地调试比在日志有限的情况下尝试和测试它们要容易得多。

检查 location 达到 null 值的情况以查找错误来源。