0

트러 플 3.2.1로 업그레이드 한 이후로 truffle-webpack-demo을 사용하고 있었지만 오류가 발생하기 시작했습니다. 나는 new branch of the same repo을 발견하고 그곳에서 복사 된 설정을 찾았습니다. 어느 쪽이 좋을까요,하지만 지금 npm start은 다음과 같은 오류를줍니다.Truffle solidity loader 트러 플 3.2.1에서 작동하지 않습니다.

Starting the development server... 

Failed to compile. 

Error in ./contracts/MetaCoin.sol 
Module build failed: Error: You must specify the network name to deploy to. (network) 
@ ./src/components/AccountList/AccountListContainer.js 37:16-49 

나는 송로 버섯, 웹팩-DEV-서버, 웹팩와 트 뤼프 견고 로더 아래

truffle-solidity-loader: "git+https://github.com/sogoiii/truffle-solidity-loader.git#1f1e213d52f033b6863218307b8968ae68220fe1" 
truffle: 3.2.1 
webpack-dev-server: 2.4.1 
webpack: 2.2.1 

의 다음 버전으로 업그레이드 한 내 설정/webpack.config.dev.js

var path    = require('path') 
var autoprefixer  = require('autoprefixer') 
var webpack   = require('webpack') 
var HtmlWebpackPlugin = require('html-webpack-plugin') 
var precss   = require('precss') 

// TODO: hide this behind a flag and eliminate dead code on eject. 
// This shouldn't be exposed to the user. 
var isInNodeModules = path.basename(path.resolve(path.join(__dirname, '..', '..'))) === 'node_modules' 
var relativePath = isInNodeModules ? '../../..' : '..' 
var isInDebugMode = process.argv.some(arg => 
    arg.indexOf('--debug-template') > -1 
) 

if (isInDebugMode) { 
    relativePath = '../template' 
} 

var srcPath   = path.resolve(__dirname, relativePath, 'src') 
var nodeModulesPath = path.join(__dirname, '..', 'node_modules') 
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html') 
var faviconPath  = path.resolve(__dirname, relativePath, 'favicon.ico') 
var buildPath  = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build') 

var provided = { 
    'Web3': 'web3' 
} 

module.exports = { 
    devtool: 'eval', 
    entry: [ 
    require.resolve('webpack-dev-server/client') + '?http://localhost:3000', 
    require.resolve('webpack/hot/dev-server'), 
    path.join(srcPath, 'index') 
    ], 
    output: { 
    // Next line is not used in dev but WebpackDevServer crashes without it: 
    path: buildPath, 
    pathinfo: true, 
    filename: 'bundle.js', 
    publicPath: '/' 
    }, 
    resolve: { 
    root: srcPath, 
    extensions: ['', '.js'], 
    alias: { 
     contracts: path.resolve('contracts'), 
     // config: require('../truffle').networks.development, 
     config: path.resolve('truffle.js') 
    } 
    }, 
    module: { 
    preLoaders: [ 
     { 
     test: /\.js$/, 
     loader: 'eslint', 
     include: srcPath 
     } 
    ], 
    loaders: [ 
     { 
     test: /\.js$/, 
     include: srcPath, 
     loader: 'babel', 
     query: require('./babel.dev') 
     }, 
     { 
     test: /\.css$/, 
     include: srcPath, 
     loader: 'style!css!postcss' 
     }, 
     { 
     test: /\.json$/, 
     loader: 'json' 
     }, 
     { 
     test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/, 
     loader: 'file' 
     }, 
     { 
     test: /\.(mp4|webm)$/, 
     loader: 'url?limit=10000' 
     }, 
     { 
     test: /\.sol/, 
     loader: 'truffle-solidity', 
     loaders: ['json-loader', 'truffle-solidity-loader?migrations_directory=' + path.resolve(__dirname, '../migrations') + '&network=development&contracts_build_directory=' + path.resolve(__dirname, '../dist/contracts')] 
     } 
    ] 
    }, 
    eslint: { 
    configFile: path.join(__dirname, 'eslint.js'), 
    useEslintrc: false 
    }, 
    postcss: function() { 
    return [precss, autoprefixer] 
    }, 
    plugins: [ 
    new HtmlWebpackPlugin({ 
     inject: true, 
     template: indexHtmlPath, 
     favicon: faviconPath 
    }), 
    new webpack.ProvidePlugin(provided), 
    new webpack.DefinePlugin({ 
     'myEnv': JSON.stringify(require('../truffle').networks.development), 
     'process.env.NODE_ENV': '"development"' 
    }), 
    new webpack.EnvironmentPlugin(['NODE_ENV']), 
    new webpack.HotModuleReplacementPlugin() 
    ] 
} 

여기 내 MetaCoin.sol의

pragma solidity ^0.4.4; 
import "./ConvertLib.sol"; 

// This is just a simple example of a coin-like contract. 
// It is not standards compatible and cannot be expected to talk to other 
// coin/token contracts. If you want to create a standards-compliant 
// token, see: https://github.com/ConsenSys/Tokens. Cheers! 

contract MetaCoin { 
    mapping (address => uint) balances; 

    event Transfer(address indexed _from, address indexed _to, uint256 _value); 

    function MetaCoin() { 
     balances[tx.origin] = 6000000000; 
    } 

    function sendCoin(address receiver, uint amount) returns(bool sufficient) { 
     if (balances[msg.sender] < amount) return false; 
     balances[msg.sender] -= amount; 
     balances[receiver] += amount; 
     Transfer(msg.sender, receiver, amount); 
     return true; 
    } 

    function getBalanceInEth(address addr) returns(uint){ 
     return convert(getBalance(addr),2); 
    } 

    function getBalance(address addr) returns(uint) { 
     return balances[addr]; 
    } 

    function convert(uint amount,uint conversionRate) returns (uint convertedAmount) 
    { 
     return amount * conversionRate; 
    } 

} 

여기 여기 내 AccountListContainer.js

import React, { Component } from 'react' 
import AccountList from 'components/AccountList/AccountList' 
import SendCoin from 'components/SendCoin/SendCoin' 

import Contract from 'truffle-contract' 
import MetaCoinArtifact from 'contracts/MetaCoin.sol'; 
const MetaCoin = Contract(MetaCoinArtifact) 

import Web3 from 'web3'; 

const provider = new Web3.providers.HttpProvider('http://localhost:8545') 
MetaCoin.setProvider(provider); 

class AccountListContainer extends Component { 
    constructor(props) { 
    super(props) 

    this.state = { 
     accounts: [], 
     coinbase: '' 
    } 

    this._getAccountBalance = this._getAccountBalance.bind(this) 
    this._getAccountBalances = this._getAccountBalances.bind(this) 
    } 

    _getAccountBalance (account) { 
    return MetaCoin.deployed() 
     .then(meta => { 
     return meta.getBalance.call(account, {from: account}) 
     }) 
     .then(function (value) { 
     return { account: value.valueOf() } 
     }) 
     .catch(function (e) { 
     console.log(e) 
     throw e 
     }) 
    } 

    _getAccountBalances() { 
    this.props.web3.eth.getAccounts(function (err, accs) { 
     if (err != null) { 
     window.alert('There was an error fetching your accounts.') 
     console.error(err) 
     return 
     } 

     if (accs.length === 0) { 
     window.alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.") 
     return 
     } 

     this.setState({coinbase: accs[0]}) 

     var accountsAndBalances = accs.map((account) => { 
     return this._getAccountBalance(account).then((balance) => { return { account, balance } }) 
     }) 

     Promise.all(accountsAndBalances).then((accountsAndBalances) => { 
     this.setState({accounts: accountsAndBalances, coinbaseAccount: accountsAndBalances[0]}) 
     }) 
    }.bind(this)) 
    } 

    componentDidMount() { 
    const refreshBalances =() => { 
     this._getAccountBalances() 
    } 

    refreshBalances() 

    setInterval(()=>{ 
     refreshBalances(); 
     return refreshBalances 
    }, 5000) 
    } 

    render() { 
    return (
     <div> 
     <AccountList accounts={this.state.accounts} /> 
     <SendCoin sender={this.state.coinbase} /> 
     </div> 
    ) 
    } 
} 

export default AccountListContainer 

의 오류 Module build failed: Error: You must specify the network name to deploy to. (network)을 감안할 때 truffle.js

module.exports = { 
    networks: { 
    development: { 
     host: "localhost", 
     port: 8545, 
     network_id: "*" 
    }, 
    staging: { 
     host: "localhost", 
     port: 8546, 
     network_id: 1337 
    } 
    } 
}; 

답변

2

, 나는 당신의 truffle.js 파일이 새로운 송로 버섯에 업데이트되지 않은 용의자의 3 사양.

구성 변경 방법을 migration guided에서 확인하십시오. 그것은 비슷한 모양이어야합니다.

module.exports = { 
     networks: { 
     development: { 
      host: "localhost", 
      port: 8545, 
      network_id: "*" 
     }, 
     staging: { 
      host: "localhost", 
      port: 8546, 
      network_id: 1337 
     }, 
     ropsten: { 
      host: "158.253.8.12", 
      port: 8545, 
      network_id: 3 
     } 
     } 
    };