【问题标题】:Can't deploy smart contract application to Heroku无法将智能合约应用程序部署到 Heroku
【发布时间】:2021-09-23 12:46:49
【问题描述】:

我的应用程序是使用 Truffle 和 React 构建的,当我尝试部署到 Heroku 时出现错误。在我的本地机器上一切正常,但是当我尝试部署时:

 /tmp/build_e68c9473/node_modules/truffle/build/724.bundled.js:11740
         } catch {
                 ^
       
       SyntaxError: Unexpected token {
           at createScript (vm.js:80:10)
           at Object.runInThisContext (vm.js:139:10)
           at Module._compile (module.js:616:28)
           at Object.Module._extensions..js (module.js:663:10)
           at Module.load (module.js:565:32)
           at tryModuleLoad (module.js:505:12)
           at Function.Module._load (module.js:497:3)
           at Module.require (module.js:596:17)
           at require (internal/module.js:11:18)
           at Object.__webpack_require__.f.require (/tmp/build_e68c9473/node_modules/truffle/build/cli.bundled.js:624:28)
       Error: Error while attempting to download and cache solc 0.5.16: Command failed: node ./build/cli.bundled.js obtain --solc=0.5.16
       /tmp/build_e68c9473/node_modules/truffle/build/724.bundled.js:11740
         } catch {
                 ^
       
       SyntaxError: Unexpected token {
           at createScript (vm.js:80:10)
           at Object.runInThisContext (vm.js:139:10)
           at Module._compile (module.js:616:28)
           at Object.Module._extensions..js (module.js:663:10)
           at Module.load (module.js:565:32)
           at tryModuleLoad (module.js:505:12)
           at Function.Module._load (module.js:497:3)
           at Module.require (module.js:596:17)
           at require (internal/module.js:11:18)
           at Object.__webpack_require__.f.require (/tmp/build_e68c9473/node_modules/truffle/build/cli.bundled.js:624:28)
       
           at postinstallObtain (/tmp/build_e68c9473/node_modules/truffle/scripts/postinstall.js:13:11)
           at Object.<anonymous> (/tmp/build_e68c9473/node_modules/truffle/scripts/postinstall.js:20:3)
           at Module._compile (module.js:652:30)
           at Object.Module._extensions..js (module.js:663:10)
           at Module.load (module.js:565:32)
           at tryModuleLoad (module.js:505:12)
           at Function.Module._load (module.js:497:3)
           at Function.Module.runMain (module.js:693:10)
           at startup (bootstrap_node.js:188:16)
           at bootstrap_node.js:609:3
       added 4014 packages in 103.484s
       
-----> Build
       Running build
       
       > mtc-dex@0.2.0 build /tmp/build_e68c9473
       > react-scripts build
       
/tmp/build_e68c9473/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
      } catch {
              ^
SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/tmp/build_e68c9473/node_modules/fs-extra/lib/mkdirs/index.js:3:44)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mtc-dex@0.2.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mtc-dex@0.2.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.7ibpv/_logs/2021-07-14T09_25_41_172Z-debug.log
-----> Build failed

在安装依赖项时,我在构建开始之前看到了一些错误。在 Heroku 上安装 truffle 时,我的印象是有些问题,但我不确定。之后,它会在构建时崩溃。

我必须指出,我能够在我的本地计算机上运行 npm run build 而没有任何错误。

这是我的 package.json:

{
  "name": "mtc-dex",
  "version": "0.2.0",
  "description": "Decentralized Ethereum Token Exchange",
  "author": "miqueltrallero.c@gmail.com",
  "private": true,
  "homepage": ".",
  "engines": {
    "node": "10.19.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "dependencies": {
    "@reduxjs/toolkit": "^1.6.0",
    "@truffle/hdwallet-provider": "^1.4.1",
    "apexcharts": "^3.27.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "babel-register": "^6.26.0",
    "bootstrap": "^5.0.2",
    "chai": "^4.3.4",
    "chai-as-promised": "^7.1.1",
    "chai-bignumber": "^3.0.0",
    "dotenv": "^10.0.0",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "openzeppelin-solidity": "^4.2.0",
    "react": "^17.0.2",
    "react-apexcharts": "^1.3.9",
    "react-bootstrap": "^1.6.1",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.4",
    "react-scripts": "^4.0.3",
    "solc": "^0.8.6",
    "solidity-coverage": "^0.7.16",
    "truffle": "^5.3.14",
    "truffle-flattener": "^1.5.0",
    "truffle-hdwallet-provider-privkey": "^0.3.0",
    "web3": "^1.4.0"
  }
}

【问题讨论】:

    标签: node.js reactjs heroku npm truffle


    【解决方案1】:

    确保在部署时不包括 node_modules 文件夹。如果不是这种情况,请尝试设置config vars

    【讨论】:

      【解决方案2】:

      所以基本上当heroku 尝试构建您的项目时,它会遇到错误。

       /tmp/build_e68c9473/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
            } catch {
                    ^
       SyntaxError: Unexpected token {
      

      这个错误最可能的原因是try/catch块的语法如下:

      try {
        ...
      } catch (error) {
        ...
      }
      

      尝试在 catch{ 之间添加 (error) 任何你有 try/catch 块的地方。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-25
        • 2022-08-23
        • 2012-10-30
        • 2017-07-29
        • 1970-01-01
        相关资源
        最近更新 更多