我无法理解“找不到模块:错误:无法解析'fs''”

时间:2019-10-28 22:38:12

标签: javascript reactjs typescript babeljs

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

无论我花多少精力进行配置,我都无法使构建阶段正常工作并出现以下错误:

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
  • 构建

有人可以告诉我我做错了什么吗? 预先谢谢你。

1 个答案:

答案 0 :(得分:1)

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

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