question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SOLVED: Webpack warning about not found "fs" module

See original GitHub issue

I get the following warning when building my webapp with webpack:

[1] WARNING in ../node_modules/tfjs-image-recognition-base/build/es6/env/initialize.js
[1] Module not found: Error: Can't resolve 'fs' in '/Users/username/project/node_modules/tfjs-image-recognition-base/build/es6/env'
[1]  @ ../node_modules/tfjs-image-recognition-base/build/es6/env/initialize.js
[1]  @ ../node_modules/tfjs-image-recognition-base/build/es6/env/index.js
[1]  @ ../node_modules/tfjs-image-recognition-base/build/es6/index.js
[1]  @ ../node_modules/face-api.js/build/es6/index.js
[1]  @ ./src/index.tsx

I had to add the following to my webpack config to suppress the warning:

node: {
   fs: "empty"
}

It’s weird because the target in my webpack config is set to web.

Am I doing something wrong? If not, this issue may help other people with the same warning.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
maccuaacommented, Nov 18, 2020

For webpack 5 you need:

resolve: {
    fallback: {
      fs: false
    }
  }

This really should be fixed in this lib though. Having to do this in my webpack config is clunky.

4reactions
justadudewhohackscommented, Dec 1, 2018

Thanks for reporting your solution!

It’s because webpack sees the require(‘fs’) in the code, but although it won’t be required in a browser environment. face-api.js is not only a library for the browser anymore, if you are running in a nodejs environment fs will be required and used for reading model files from disk.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'fs' in - Stack Overflow
For me the solution was to add this to the webpack config: config.node = { fs: 'empty', }. Another solution if you use...
Read more >
Module not found: Can't resolve 'fs' error [Solved] | bobbyhadz
The error "Module not found: Error: Can't resolve 'fs'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
module not found error can't resolve 'fs' react js - You.com
Here is a full solution to end the 'fs' error once and for all. In theory, you can do the following: Eject your...
Read more >
Next.js + Webpack - Fix for ModuleNotFoundError: Module not ...
To fix the error with Webpack 4, update your Next.js config file ( /next.config.js ) with the following, it tells webpack to set...
Read more >
Module Methods - webpack
This section covers all methods available in code compiled with webpack. ... No CommonJS allowed, for example, you can't use require , module.exports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found