Netlify React 构建失败但它在本地工作

Netlfy React build fails but it works localy

当我 运行 在 Netlify 上构建时它失败了,但是当我 运行 它在我的本地 windows PC 上时它 运行 就像一个魅力

这是 Netlify 输出(当 Netlify 运行s 构建命令时发生错误):

10:32:27 PM: Build ready to start
10:32:29 PM: build-image version: 3031d4c9e432fd7016f6279fc9ad706f9205d845
10:32:29 PM: build-image tag: v3.3.17
10:32:29 PM: buildbot version: 1f35b3abd6e2bf5230d8edf68072840fdec1513f
10:32:29 PM: Fetching cached dependencies
10:32:30 PM: Failed to fetch cache, continuing with build
10:32:30 PM: Starting to prepare the repo for build
10:32:30 PM: No cached dependencies found. Cloning fresh repo
10:32:30 PM: git clone https://github.com/ChristofferHennie/api-webapp-easyapi
10:32:31 PM: Preparing Git Reference refs/heads/master
10:32:32 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus 'build/' in the Netlify UI
10:32:32 PM: Starting build script
10:32:32 PM: Installing dependencies
10:32:32 PM: Python version set to 2.7
10:32:34 PM: v12.18.0 is already installed.
10:32:34 PM: Now using node v12.18.0 (npm v6.14.4)
10:32:34 PM: Started restoring cached build plugins
10:32:35 PM: Finished restoring cached build plugins
10:32:35 PM: Attempting ruby version 2.7.1, read from environment
10:32:36 PM: Using ruby version 2.7.1
10:32:36 PM: Using PHP version 5.6
10:32:36 PM: 5.2 is already installed.
10:32:36 PM: Using Swift version 5.2
10:32:36 PM: Started restoring cached node modules
10:32:36 PM: Finished restoring cached node modules
10:32:37 PM: Installing NPM modules using NPM version 6.14.4
10:33:09 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
10:33:09 PM: > node -e "try{require('./postinstall')}catch(e){}"
10:33:09 PM: > core-js@3.6.5 postinstall /opt/build/repo/node_modules/core-js
10:33:09 PM: > node -e "try{require('./postinstall')}catch(e){}"
10:33:09 PM: > core-js-pure@3.6.5 postinstall /opt/build/repo/node_modules/core-js-pure
10:33:09 PM: > node -e "try{require('./postinstall')}catch(e){}"
10:33:11 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
10:33:11 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:33:11 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
10:33:11 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:33:11 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
10:33:11 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:33:11 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
10:33:11 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:33:11 PM: added 1679 packages from 795 contributors and audited 1683 packages in 33.786s
10:33:13 PM: 59 packages are looking for funding
10:33:13 PM:   run `npm fund` for details
10:33:13 PM: found 1 low severity vulnerability
10:33:13 PM:   run `npm audit fix` to fix them, or `npm audit` for details
10:33:13 PM: NPM modules installed
10:33:13 PM: Started restoring cached go cache
10:33:13 PM: Finished restoring cached go cache
10:33:13 PM: go version go1.14.4 linux/amd64
10:33:13 PM: go version go1.14.4 linux/amd64
10:33:13 PM: Installing missing commands
10:33:13 PM: Verify run directory
10:33:15 PM: ​
10:33:15 PM: ┌─────────────────────────────┐
10:33:15 PM: │        Netlify Build        │
10:33:15 PM: └─────────────────────────────┘
10:33:15 PM: ​
10:33:15 PM: ❯ Version
10:33:15 PM:   @netlify/build 2.0.10
10:33:15 PM: ​
10:33:15 PM: ❯ Flags
10:33:15 PM:   deployId: 5ef266db8af236000856f030
10:33:15 PM:   mode: buildbot
10:33:15 PM: ​
10:33:15 PM: ❯ Current directory
10:33:15 PM:   /opt/build/repo
10:33:15 PM: ​
10:33:15 PM: ❯ Config file
10:33:15 PM:   No config file was defined: using default values.
10:33:15 PM: ​
10:33:15 PM: ❯ Context
10:33:15 PM:   production
10:33:15 PM: ​
10:33:15 PM: ┌────────────────────────────────┐
10:33:15 PM: │ 1. Build command from settings │
10:33:15 PM: └────────────────────────────────┘
10:33:15 PM: ​
10:33:15 PM: $ npm run build
10:33:15 PM: > api-webapi-easyapi@0.1.0 build /opt/build/repo
10:33:15 PM: > react-scripts build
10:33:16 PM: Creating an optimized production build...
10:33:19 PM: Failed to compile.
10:33:19 PM: 
10:33:19 PM: ./src/App.js
10:33:19 PM: Cannot find file './components/pages/About' in './src'.
10:33:19 PM: npm ERR! code ELIFECYCLE
10:33:19 PM: npm ERR! errno 1
10:33:19 PM: npm ERR! api-webapi-easyapi@0.1.0 build: `react-scripts build`
10:33:19 PM: npm ERR! Exit status 1
10:33:19 PM: npm ERR!
10:33:19 PM: npm ERR! Failed at the api-webapi-easyapi@0.1.0 build script.
10:33:19 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
10:33:19 PM: npm ERR! A complete log of this run can be found in:
10:33:19 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-06-23T20_33_19_677Z-debug.log
10:33:19 PM: ​
10:33:19 PM: ┌─────────────────────────────┐
10:33:19 PM: │   "build.command" failed    │
10:33:19 PM: └─────────────────────────────┘
10:33:19 PM: ​
10:33:19 PM:   Error message
10:33:19 PM:   Command failed with exit code 1: npm run build
10:33:19 PM: ​
10:33:19 PM:   Error location
10:33:19 PM:   In Build command from settings:
10:33:19 PM:   npm run build
10:33:19 PM: ​
10:33:19 PM:   Resolved config
10:33:19 PM:   build:
10:33:19 PM:     command: npm run build
10:33:19 PM:     publish: /opt/build/repo/build
10:33:19 PM: Caching artifacts
10:33:19 PM: Started saving node modules
10:33:19 PM: Finished saving node modules
10:33:19 PM: Started saving build plugins
10:33:19 PM: Finished saving build plugins
10:33:19 PM: Started saving pip cache
10:33:27 PM: Finished saving pip cache
10:33:27 PM: Started saving emacs cask dependencies
10:33:27 PM: Finished saving emacs cask dependencies
10:33:27 PM: Started saving maven dependencies
10:33:27 PM: Finished saving maven dependencies
10:33:27 PM: Started saving boot dependencies
10:33:27 PM: Finished saving boot dependencies
10:33:27 PM: Started saving go dependencies
10:33:27 PM: Finished saving go dependencies
10:33:30 PM: Error running command: Build script returned non-zero exit code: 1
10:33:30 PM: Failing build: Failed to build site
10:33:30 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
10:33:30 PM: Finished processing build request in 1m0.370032766s

第4行的app.js里面说导入错误,但是我找不到。在我看来,这是应该的。

import React, { useState } from 'react'
import { BrowserRouter as Router, Route } from "react-router-dom"
import Header from "./components/Header"
import About from "./components/pages/About"
import GetData from "./components/GetData"
import DisplayData from "./components/DisplayData";
import Payload from "./components/Payload"
import "./App.css"

const App = () => {
  const [data, setData] = useState({})
  const [payload, setPayload] = useState({})

  return (
    <Router>
      <Header/>
      <Route exact path="/" render={props => (
        <div className="home">
          <GetData setData={setData} payload={payload}/>
          <div className="main">
            <Payload setPayload={setPayload} payload={payload}/>
            <DisplayData data={data}/>
          </div>
        </div>
      )}/>
      <Route path="/about" component={About}/>
    </Router>
  )
}

export default App;

它指向的文件只是一个简单的占位符:

import React from 'react';

const About = () => {
  return (
    <div>
      <h1>About</h1>
    </div>
  );
};

export default About;

提前感谢您的帮助!

更新 #1

我发现了漏洞。发生错误,因此 GitHub 未注册页面目录将名称从“页面”更改为“页面”

只是看了看日志,文件中的 code 似乎没有任何问题,它抱怨根本找不到文件。具体原因取决于您的构建设置,但我的第一个猜测是您尚未签入 components/pages/About 或自签入后尚未推送到您的仓库。

建议您可以下载构建或(从构建中获取文件列表)来调查猜测。

据我所知,“组件”目录中没有“页面”目录

10:33:19 PM: ./src/App.js
10:33:19 PM: Cannot find file './components/pages/About' in './src'.

所以你必须改变:

import About from "./components/pages/About"

收件人(取决于您的回购协议中的内容):

import About from "./components/Pages/About"