I cannot understand “ Module not found: Error: Can't resolve 'fs' '”

…衆ロ難τιáo~ 提交于 2021-01-27 20:06:15

问题


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'  

The code is entirely in https://github.com/Hedgestock/Wikiwar

Here is how to reproduce the errors:

  • 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.


回答1:


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


来源:https://stackoverflow.com/questions/58599271/i-cannot-understand-module-not-found-error-cant-resolve-fs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!