Truffle Webpack:无法解析'模块'在require-from-string中

时间:2017-11-24 10:35:12

标签: javascript webpack truffle

在编译期间,当在以下位置进行require调用时会发生这种情况:

错误指向声明此行的行:

var Module = require('module');

这是在require-from-string的index.js中 实际上我可以在任何地方继续引起错误。

我已经使用npm安装了模块,并且我的node_modules中存在模块。

我的webpack.config.js:

const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack')
const standardOptions = require('./package.json').standard

const environment = process.env.NODE_ENV || 'development'
const $ = {}
const modulePattern = /(node_modules|bower_components)/

module.exports = {
  node: {
    fs: 'empty'
  },
  entry: './app/javascript/app.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'app.js'
  },
  plugins: [
    // Copy our app's index.html to the build folder.
    new CopyWebpackPlugin([
      { from: './app/index.html', to: "index.html" }
    ])
  ],
  module: {
    rules: [
      {
       test: /\.css$/,
       use: [ 'style-loader', 'css-loader', "postcss-loader" ]
      }
    ],
    loaders: [
      { test: /\.json$/, use: 'json-loader' },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015'],
          plugins: ['transform-runtime']
        }
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

   module.exports = {  
  node: {
     fs: 'empty',    
     module : 'empty'
      },