Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何解决使用react和next.js时找不到fs模块的错误_Node.js_Reactjs_Next - Fatal编程技术网

Node.js 如何解决使用react和next.js时找不到fs模块的错误

Node.js 如何解决使用react和next.js时找不到fs模块的错误,node.js,reactjs,next,Node.js,Reactjs,Next,我正在使用一个没有路由器设置的react应用程序。我想构建我的sitemap.xml文件。我尝试了一些模块,比如sitemap.js、react路由器sitemap、sitemap生成器。但由于fs模块丢失,这些模块正在抛出错误。我通过npm安装--save安装了fs模块。但它仍然显示出错误 我在一些论坛上找到了在webpack.config文件中添加以下代码的方法 节点:{ 财政司司长:空置 } 我不确定这个文件在哪里。我在站点地图相关模块中找不到它们 请帮我解决这个问题。我还没有反应过来 这

我正在使用一个没有路由器设置的react应用程序。我想构建我的sitemap.xml文件。我尝试了一些模块,比如sitemap.js、react路由器sitemap、sitemap生成器。但由于fs模块丢失,这些模块正在抛出错误。我通过
npm安装--save
安装了fs模块。但它仍然显示出错误

我在一些论坛上找到了在webpack.config文件中添加以下代码的方法

节点:{ 财政司司长:空置 } 我不确定这个文件在哪里。我在站点地图相关模块中找不到它们

请帮我解决这个问题。我还没有反应过来

这是我的文件夹结构。

创建next.config.js并将其放在下面的代码中。这对我来说很好

next.config.js
React是一个前端库
fs
是后端文件系统节点库。你想在React中做前端的
fs
工作吗?请添加您迄今为止所做工作的相关最低代码。我不使用fs模块。但是我可以找到const fs=require('fs');在站点地图生成器模块内部。我在上面使用fs ModuleEyes列出的站点地图生成模块,但这些站点地图库将使用
fs
模块。如果您尝试在前端文件中使用它们,那么它们将尝试在浏览器中运行,您将收到该错误消息。在使用其中一个模块时,您尝试在哪些文件中创建站点地图?请检查我已更新的文件夹结构。我正在运行pages/index.js文件中的站点地图脚本,我假设
index.js
文件是你的React应用程序的根?
module.exports = {
    webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
      // Note: we provide webpack above so you should not `require` it
      // Perform customizations to webpack config
      // Important: return the modified config

      // Example using webpack option
      //config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
      config.node = {fs:"empty"}
      return config
    },
    webpackDevMiddleware: config => {
      // Perform customizations to webpack dev middleware config
      // Important: return the modified config
      return config
    },
  }