早午餐建立,但 "Cannot find module 'buffer'" 开放

Brunch builds but "Cannot find module 'buffer'" on open

我们正在尝试将我们的前端构建转换为使用 Brunch。这是我目前的早午餐配置:

module.exports = {

  files: {
    javascripts: {
      joinTo: {
        'vendor.js': /^(?!source)/,
        'app.js': /^source/
      },
      entryPoints: {
        'source/scripts/app.jsx': 'app.js'
      }
    },
    stylesheets: {joinTo: 'core.css'},
  },

  paths: {
    watched: ['source']
  },

  modules: {
    autoRequire: {
      'app.js': ['source/scripts/app']
    }
  },

  plugins: {
    babel: {presets: ['latest', 'react']},
    postcss: {processors: [require('autoprefixer')]},
    assetsmanager: {
      copyTo: {
        'assets': ['source/resources/*']
      }
    },
    static: {
      processors: [
        require('html-brunch-static')({
          processors: [
            require('pug-brunch-static')({
              fileMatch: 'source/views/home.pug',
              fileTransform: (filename) => {
                filename = filename.replace(/\.pug$/, '.html');
                filename = filename.replace('views/', '');
                return filename;
              }
            })
          ]
        })
      ]
    }

  }

};

我将 modules.autoRequire 部分添加到早午餐配置中,然后开始出现以下错误。没有 modules.autoRequire 我没有控制台错误,但我的网络应用程序也没有启动。 运行 brunch build 结果没有错误,但是当我打开构建的网站时,出现错误

Uncaught Error: Cannot find module 'buffer' from 'lodash/lodash.js'

堆栈跟踪中的第一行将我指向 vendor.js

中的这个函数
var require = function(name, loaderPath) {
  if (loaderPath == null) loaderPath = '/';
  var path = expandAlias(name);

  if (has.call(cache, path)) return cache[path].exports;
  if (has.call(modules, path)) return initModule(path, modules[path]);

  throw new Error("Cannot find module '" + name + "' from '" + loaderPath + "'");
};

我不确定如何继续让我的构建工作。这个 issue 似乎是相关的。

如何克服这个错误? (请随时询问更多信息。我不确定哪些信息会有帮助。)

Brunch 从 package.json 中定义的(brunch 特定的)npm 包中获取构建管道的步骤。因此,请确保包含所有需要的包(或删除不需要的包)。

参见docs for more information about how to use plugins