簡體   English   中英

無法將智能合約應用程序部署到 Heroku

[英]Can't deploy smart contract application to Heroku

我的應用程序是用 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 上安裝松露時,我的印象是它不太好,但我不確定。 之后,它在進行構建時崩潰。

我必須指出,我能夠在本地機器上運行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_modules文件夾。 如果不是這種情況,請嘗試設置config vars

因此,基本上當heroku嘗試構建您的項目時,它會遇到錯誤。

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

此錯誤最可能的原因是 try/catch 塊的語法如下:

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

嘗試在catch{有 try/catch 塊的任何地方添加(error)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM