【问题标题】:Fails to deploy gatsby wordpress site on netlify无法在 netlify 上部署 gatsby wordpress 站点
【发布时间】:2021-10-12 18:20:40
【问题描述】:

需要帮助来找出下面的错误。 我尝试在 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'

【问题讨论】:

  • 是否在本地构建?
  • 我尝试通过 netlify 和 github repo 构建它。

标签: reactjs wordpress deployment gatsby netlify


【解决方案1】:

根据错误:

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:{}} 这样的东西。

正如我在 cmets 中所说,您的代码也无法在本地运行,因此在推送或部署之前首先需要在本地进行修复。在本地进行调试比在日志更有限的情况下尝试和现场测试要容易得多。

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

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 2020-01-19
    • 2021-09-10
    • 2019-12-23
    • 2020-05-29
    • 2020-06-20
    • 2019-10-18
    • 2020-12-13
    • 2021-08-16
    相关资源
    最近更新 更多