我不明白“找不到模块:错误:无法解析'fs''" [英] I cannot understand " Module not found: Error: Can't resolve 'fs' '"

查看:60
本文介绍了我不明白“找不到模块:错误:无法解析'fs''"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Having a little spare time I have tried reworking an old project of mine with new web techs that I like (Typescript, Pug and React). Everything worked fine until I tried adding pug.js into the mix with babel-plugin-transform-react-pug.

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

No matter how much I fiddle with the configurations I can't get the build phase to work and get the following errors:

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

以下是重现错误的方法:

Here is how to reproduce the errors:

  • 转到 frontend 文件夹的根目录
  • 进行安装( npm i )
  • 使用 npx webpack
  • 进行构建
  • Go to the root of the frontend folder,
  • Do an install (npm i)
  • Build with npx webpack

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

Could someone tell me what I'm doing wrong? Thank you in advance.

推荐答案

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

You could also run into this issue when your platform doesn't support file-system. SO try add this line to your webpack.config.js to add the corresponding pollyfills:

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

这篇关于我不明白“找不到模块:错误:无法解析'fs''"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆