razzle 无法解析 'fs' / 'net'(服务器端渲染 React 应用程序)

razzle Can't resolve 'fs' / 'net' (server side rendering react app)

目前正在使用https://github.com/jaredpalmer/razzle实现一个React应用的SSR。 运行 在我的节点模块中出现以下错误:

还有这个

我添加了一个 razzle.config.js 来自定义 razzle 配置,使其看起来像这样(如下),代码仍然不是 运行。

module.exports = {
  target: 'node',
  node: {
    console: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};

知道为什么我会收到错误消息以及我可以采取什么措施来解决吗?

如果你想扩展Webpack配置,你需要使用modify function of the razzle.config.js export

例子

module.exports = {
  modify: config => {
    config.node = { fs: "empty" };
    return config;
  }
};