【问题标题】:Heroku Failed to Compile during buildHeroku 在构建期间无法编译
【发布时间】:2021-05-25 11:54:35
【问题描述】:

请帮忙。我无法部署到我的 Heroku 应用程序。我无法成功构建并部署到 Heroku。

无法在我的所有类组件上编译

remote:        Failed to compile.
remote:
remote:        ./src/contexts/shopify/ShopContext.js
remote:          Line 14:3:   'state' is not defined                        no-undef
remote:          Line 28:3:   'fetchShopInfo' is not defined                no-undef
remote:          Line 34:3:   'createCheckout' is not defined               no-undef
remote:          Line 40:3:   'fetchCheckoutById' is not defined            no-undef
remote:          Line 49:3:   'addVariantToCart' is not defined             no-undef
remote:          Line 67:3:   'updateQuantityInCart' is not defined         no-undef
remote:          Line 81:3:   'removeLineItemInCart' is not defined         no-undef
remote:          Line 91:3:   'fetchAllProducts' is not defined             no-undef
remote:          Line 97:3:   'fetchProductById' is not defined             no-undef
remote:          Line 103:3:  'sortProductsByTitle' is not defined          no-undef
remote:          Line 120:3:  'fetchProductsByCollectionId' is not defined  no-undef
remote:          Line 131:3:  'handleCartClose' is not defined              no-undef
remote:          Line 135:3:  'handleCartOpen' is not defined               no-undef
remote:
remote:        Search for the keywords to learn more about each error.
remote:
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the [appname]@3.0.1-SNAPSHOT build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.WEaEj/_logs/2021-02-23T05_44_14_298Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! [appname]@1.0.0 heroku-postbuild: npm install --prefix client && npm run build --prefix client
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the[appname]@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.WEaEj/_logs/2021-02-23T05_44_14_319Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 434f626f0467fb3d0d901ba80346bcc3da21c7c7
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 434f626f0467fb3d0d901ba80346bcc3da21c7c7
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main

这是类组件

class ShopProvider extends Component {
  state = {
    products: [],
    productsCollection: [],
    product: {},
    checkout: { lineItems: [] },
    isCartOpen: false,
    shop: {},
  };

  componentDidMount() {
    this.createCheckout();
    this.fetchShopInfo();
  }

  fetchShopInfo = async () => {
    const shopInfo = await client.shop.fetchInfo();

    this.setState({ shop: shopInfo });
  };

  createCheckout = async () => {
    const checkout = await client.checkout.create();

    this.setState({ checkout: checkout });
  };

  fetchCheckoutById = async (checkoutId) => {
    try {
      return await client.checkout.fetch(checkoutId);
    } catch (error) {
      console.error(error);
      return null;
    }
  };

  addVariantToCart = async (variantId, quantity) => {
    this.setState({ isCartOpen: true });

    const lineItemsToAdd = [
      {
        variantId,
        quantity: parseInt(quantity, 10),
      },
    ];

    const checkout = await client.checkout.addLineItems(
      this.state.checkout.id,
      lineItemsToAdd,
    );

    this.setState({ checkout: checkout });
  };

  updateQuantityInCart = async (lineItemId, quantity) => {
    const checkoutId = this.state.checkout.id;
    const lineItemsToUpdate = [
      { id: lineItemId, quantity: parseInt(quantity, 10) },
    ];

    const newCheckout = await client.checkout.updateLineItems(
      checkoutId,
      lineItemsToUpdate,
    );

    this.setState({ checkout: newCheckout });
  };

  removeLineItemInCart = async (lineItemId) => {
    const checkoutId = this.state.checkout.id;

    const newCheckout = await client.checkout.removeLineItems(checkoutId, [
      lineItemId,
    ]);

    this.setState({ checkout: newCheckout });
  };

  fetchAllProducts = async () => {
    const products = await client.product.fetchAll();

    this.setState({ products: products });
  };

  fetchProductById = async (productId) => {
    const product = await client.product.fetch(productId);

    this.setState({ product: product });
  };

  sortProductsByTitle = (products) => {
    if (!products) return null;

    return products.sort((a, b) => {
      const titleA = a.title.toUpperCase();
      const titleB = b.title.toUpperCase();
      if (titleA < titleB) {
        return -1;
      }
      if (titleA > titleB) {
        return 1;
      }

      return 0;
    });
  };

  fetchProductsByCollectionId = async (collectionId) => {
    const collection = await client.collection.fetchWithProducts(collectionId, {
      productsFirst: 30,
    });

    this.setState({
      productsCollection: this.sortProductsByTitle(collection.products),
    });
  };

  handleCartClose = () => {
    this.setState({ isCartOpen: false });
  };

  handleCartOpen = () => {
    this.setState({ isCartOpen: true });
  };

  render() {
    return (
      <ShopContext.Provider
        value={{
          ...this.state,
          fetchCheckoutById: this.fetchCheckoutById,
          fetchAllProducts: this.fetchAllProducts,
          fetchProductById: this.fetchProductById,
          addVariantToCart: this.addVariantToCart,
          fetchProductsByCollectionId: this.fetchProductsByCollectionId,
          updateQuantityInCart: this.updateQuantityInCart,
          removeLineItemInCart: this.removeLineItemInCart,
          handleCartClose: this.handleCartClose,
          handleCartOpen: this.handleCartOpen,
          client: client,
        }}
      >
        {this.props.children}
      </ShopContext.Provider>
    );
  }
}

我尝试重构组件并将其更改为功能组件,现在我的所有类组件现在都无法编译。

       Failed to compile.
       
       ./src/AppTopbar.js
         Line 5:10:  'defaultProps' is not defined  no-undef
         Line 9:10:  'propTypes' is not defined     no-undef
       
       Search for the keywords to learn more about each error.

【问题讨论】:

  • 分享完整的build.log。分享您的package.json。它们提供了需要安装哪些软件包的信息。构建日志包含这些软件包是否已成功安装的信息。您显示了ShopProvider,但没有显示ShopContext。你说你试图重构,但现在你所有的类都无法编译。您必须确保它首先在本地运行。
  • 我有同样的问题,今天才弹出,我在这个项目上工作了一年多,今天在部署时突然出现了这个错误。我需要帮助!
  • remote: ./src/components/Expenses/AddTransactionGP.js remote: Line 10:5: 'state' is not defined no-undef remote: Line 32:5: 'handelClick' is not defined no-undef 但是,该项目在本地运行,我正在部署相同的代码,只是在另一个文件中稍作改动。经过多次尝试后,我开始向有问题的文件添加一个构造函数并用普通函数更改箭头函数,它适用于该文件,但另一个文件显示相同的错误,所以我将不得不重构所有文件,这不会有意义。
  • @YahiaBadr,同样。很高兴我不是唯一一个。我也在这个项目上工作了将近一年,我是唯一一个推送和部署到 heroku 的人。是的,该项目也在本地运行。我已经重构了一个类组件但是另一个文件显示了相同的错误。我还有 31 个文件,不敢更改它们。请告诉我你是如何解决的。
  • @TinNguyen,先生,是的,该项目在本地运行。只有当我尝试将其推送到 Heroku 时它才会失败。

标签: reactjs class heroku deployment components


【解决方案1】:

我认为这是 Heroku 本身的问题,我尝试重新部署,它在没有添加或删除一行代码的情况下工作。

【讨论】:

    猜你喜欢
    • 2020-09-07
    • 2019-04-01
    • 2018-09-20
    • 2016-07-01
    • 2019-02-24
    • 2017-12-03
    • 2019-06-21
    • 1970-01-01
    • 2011-05-12
    相关资源
    最近更新 更多