[英]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.