In creat-react-app, in src folder, I have a database folder, with new.db file, and sql.js file with the following code in the sql.js file:
import sqlite3 from 'sqlite3';
const path = new URL('new.db', import.meta.url).pathname;
const db = new sqlite3.Database(path);
db.run('CREATE TABLE IF NOT EXISTS newTable (id INTEGER PRIMARY KEY, name TEXT, password TEXT)');
export default db;
Then, in App.js I have the following code:
import db from "../../database/sql";
function App() {
return (
<p>Hello, World!</p>
);
}
export default App;
The problem is that it throws me a couple of errors:
ERROR in ./node_modules/bindings/bindings.js 5:9-22 Module not found: Error: Can't resolve 'fs' in 'D:projectssecond_practicemy-appnode_modulesbindings' ERROR in ./node_modules/bindings/bindings.js 6:9-24 Module not found: Error: Can't resolve 'path' in 'D:projectssecond_practicemy-appnode_modulesbindings'
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 } ERROR in ./node_modules/file-uri-to-path/index.js 5:10-29 Module not found: Error: Can't resolve 'path' in 'D:projectssecond_practicemy-appnode_modulesfile-uri-to-path'
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 } ERROR in ./node_modules/sqlite3/lib/sqlite3.js 1:13-28 Module not found: Error: Can't resolve 'path' in 'D:projectssecond_practicemy-appnode_modulessqlite3lib'
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 } ERROR in ./node_modules/sqlite3/lib/trace.js 2:13-28 Module not found: Error: Can't resolve 'util' in 'D:projectssecond_practicemy-appnode_modulessqlite3lib'
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: { "util": require.resolve("util/") }'
- install 'util' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "util": false }
I tried to add this in package.json:
"browser": {"fs": false, "path": false, "os": false}`
but it didn’t help. Then I tried to add this code in config.overrides.js after installing necessary dependencies (and changing react scripts to react-app rewired start and etc.):
const webpack = require('webpack');
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"assert": require.resolve("assert"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"os": require.resolve("os-browserify"),
"url": require.resolve("url")
})
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})
])
return config;
}
And none of them much of a help, the same couple of errors throws onto screen.