繁体   English   中英

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

[英]how to solve the error that fs module is not found when used react and next.js

我正在使用没有路由器设置的React应用程序。 我想构建我的sitemap.xml文件。 我尝试了一些模块,例如sitemap.js,react-router-sitemap,sitemap-generator。 但是这些模块由于缺少fs模块而引发错误。 我通过npm install --save安装了fs模块。 但是它仍然显示错误。

我在一些论坛中发现在webpack.config文件中添加以下代码。

节点:{fs:“空”}不确定此文件在哪里。 我在站点地图相关模块旁边找不到它们。

请帮助我解决此问题。 是新来的反应。

这是我的文件夹结构。 在此处输入图片说明

创建next.config.js并放在下面的代码中。 这对我来说可以。

next.config.js

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
    },
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM