This line const { Client } = require('pg');
causes my project to throw errors. The import just mentioned, is found in my file called Logic.jsx.
In another file called Members.jsx
, I am importing the file with th pg connection like this: import DB from './Logic';
If I remove/outcomment the import of DB, all goes well, and no errors are thrown.
At first I thought that it was because the connectionstring was invalid, but that is not the case. My connectionstring looks like this.
const { Client } = require('pg');
const client = new Client({
user: 'postgres',
host: 'localhost',
database: 'teamdk',
password: '123456',
port: 5432,
});
I installed pg like this: npm install pg
in vs code
If I do this: psql -h localhost -p 5432 -d teamdk -U postgres
in the terminal, I am able to connect to my database. So it seems that the problem lies only in this: const { Client } = require('pg');
. I have spent a couple of days now, searching for a solution to the problem.
In case it might be helpfull, here is some of the errors that are thrown.
Compiled with problems:
ERROR in ./node_modules/pg-connection-string/index.js 72:69-82
Module not found: Error: Can't resolve 'fs' in 'C:teamdknode_modulespg-connection-string'
ERROR in ./node_modules/pg/lib/connection-parameters.js 3:10-24
Module not found: Error: Can't resolve 'dns' in 'C:teamdknode_modulespglib'
ERROR in ./node_modules/pg/lib/connection.js 3:10-24
Module not found: Error: Can't resolve 'net' in 'C:teamdknode_modulespglib'
ERROR in ./node_modules/pg/lib/crypto/utils-legacy.js 5:19-36
Module not found: Error: Can't resolve 'crypto' in 'C:teamdknode_modulespglibcrypto'
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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
ERROR in ./node_modules/pg/lib/crypto/utils-webcrypto.js 1:19-36
Module not found: Error: Can't resolve 'crypto' in 'C:teamdknode_modulespglibcrypto'
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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }