Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Error: Can't resolve 'fs' error in React Application #15

Closed
nijatmursali opened this issue Jul 11, 2022 · 8 comments
Closed

Comments

@nijatmursali
Copy link

Hello,

I'm currently working on one project regarding implementing OpenCV, and I saw this library. I have installed it via NPM, but I'm getting the following errors when I import the library:

Compiled with problems:

ERROR in ./node_modules/@techstark/opencv-js/dist/opencv.js 77:34-47

Module not found: Error: Can't resolve 'fs' in 


ERROR in ./node_modules/@techstark/opencv-js/dist/opencv.js 78:38-53

Module not found: Error: Can't resolve 'path' in 

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }

Could you please let me know how can I solve this issue? I have created webpack.config.js file which looks like this:

const webpack = require("webpack");
const path = require("path");

module.exports = {
  mode: "development",
  entry: path.resolve(__dirname, "./src/index.js"),
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ["babel-loader"],
      },
    ],
  },
  resolve: {
    extensions: ["*", ".js", ".jsx"],
    fallback: {
      fs: false,
      path: false,
      crypto: false,
    },
    modules: ["app", "node_modules"],
    extensions: [".js", ".jsx", ".react.js"],
    mainFields: ["browser", "jsnext:main", "main"],
  },
  output: {
    path: path.resolve(__dirname, "./dist"),
    filename: "bundle.js",
  },
  devServer: {
    static: path.resolve(__dirname, "./dist"),
  },
};

But, it does not work. Do I need to have another commands to push the code to run?

@ttt43ttt
Copy link
Contributor

@nijatmursali
Copy link
Author

I have tried it, but it gives Module not found: Error: Can't resolve 'pages/notFound' when I use with webpack. What rule should I add in that case? I cannot add ./pages/notFound.jsx because I have bunch of these pages.

@ttt43ttt
Copy link
Contributor

I don't have your source code. I'm not clear what's the issue, but the above error doesn't seem to be related to opencv.js

@gowthambalashanmugam
Copy link

any solution for the above one?

@ttt43ttt
Copy link
Contributor

@gowthambalashanmugam
Copy link

@ttt43ttt Thanks for taking a look, I have posted my question here, am facing 'fs' issue
https://stackoverflow.com/questions/73435275/unable-to-use-opencv-js-in-react-native

@gowthambalashanmugam
Copy link

gowthambalashanmugam commented Aug 21, 2022

Screen Shot 2022-08-21 at 8 19 51 PM

@mdnpascual
Copy link

I also experienced this fs module not found error. I think this is related to this facebook/create-react-app#11756

The way I solved it is by switching to react-app-rewired

Step by step instruction https://stackoverflow.com/a/73661388/1862452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants