【问题标题】:I cannot understand " Module not found: Error: Can't resolve 'fs' '"我无法理解“找不到模块:错误:无法解析 'fs''”
【发布时间】:2020-02-24 05:04:50
【问题描述】:

有一点空闲时间,我尝试使用我喜欢的新 Web 技术(Typescript、Pug 和 React)来改造我的一个旧项目。一切正常,直到我尝试将 pug.js 与 babel-plugin-transform-react-pug 添加到混合中。

无论我如何摆弄配置,我都无法让构建阶段正常工作并出现以下错误:

ERROR in ./node_modules/uglify-js/tools/node.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/pug-load/index.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/jstransformer/index.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/clean-css/lib/reader/load-original-sources.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/clean-css/lib/reader/apply-source-maps.js
Module not found: Error: Can't resolve 'fs'

ERROR in ./node_modules/clean-css/lib/reader/read-sources.js
Module not found: Error: Can't resolve 'fs'  

代码完全在https://github.com/Hedgestock/Wikiwar

这里是如何重现错误:

  • 转到frontend 文件夹的根目录,
  • 进行安装 (npm i)
  • 使用npx webpack 构建

谁能告诉我我做错了什么? 提前谢谢你。

【问题讨论】:

    标签: javascript reactjs typescript webpack babeljs


    【解决方案1】:

    当您的平台不支持文件系统时,您也可能会遇到此问题。所以尝试将此行添加到您的 webpack.config.js 以添加相应的 pollyfills:

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

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 2018-06-29
      • 2022-06-20
      • 2019-05-31
      • 2017-04-18
      • 2022-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多