Home > Net >  How to use packages that require fs & path with React
How to use packages that require fs & path with React

Time:11-26

I need to use quick.db package in my ReactAPP for hook, but React don't let use FS & Path, that is require for package

I got this errors:

ERROR in ./node_modules/file-uri-to-path/index.js 5:10-29
Module not found: Error: Can't resolve 'path' in 'C:\\Users\\Moruga\\projects\\character-manager-jjk-rp\\node_modules\\file-uri-to-path'
ERROR in ./node_modules/bindings/bindings.js 5:9-22
Module not found: Error: Can't resolve 'fs' in 'C:\\Users\\Moruga\\projects\\character-manager-jjk-rp\\node_modules\\bindings'

I already try to write

"browser": {
"fs": false,
"path": false,
"os": false
},

in package.json but it don't help

CodePudding user response:

You cannot run all npm packages everywhere.

You should use node.js javascript packages only on a server, it does not run in the browser. Those packages you want to run are supposed to run only on a server (or your local machine), not in the browser. They are supposed to have access to thinks like files, network, databases, etc.

For this particular reason you cannot utilise them with React.

React app is a client side javascript package, meaning it's supposed to run in a browser without an access to the OS stuff, like files, databases, etc.

For React app to access DB, files, network or whatever, you need to have 2 separate projects. One that's running node.js (purely on server, or in terminal) and 2nd running React app. They would communicate using GET/POST network calls

  • Related