I did create-react-app and also installed sequelize and pg. But when I do npm start, I get the following error -
./node_modules/pg/lib/connection-parameters.js
Here is the App.js file -
import React, { Component } from 'react';
const Sequelize = require('sequelize');
const sequelize = new Sequelize('postgres', 'postgres', 'password', {
host: 'localhost',
dialect: 'postgres',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
class App extends Component {
render() {
return (
<div >
<p>Test</p>
</div>
);
}
}
export default App;
Also, in the package.json file, I have sequelize and pg. What could be the problem? I have tried to delete the node_modules folder and doing npm install, but no luck.
Thanks in advance.
This is happening because one of your packages uses JavaScript promises, which depend on the dns
module, which is only available in Node.js (server-side) and not when your code runs in the browser. Though the implementation depends on it, it does not require it to work, so you can solve the problem by faking the existence of the dns
module.
To do so, follow these steps:
Create a folder /src/mock/dns
. Inside this folder, create a file index.js
containing:
module.exports = {};
module.exports.default = {};
Also inside this folder, create a file package.json
containing:
{
"name": "dns",
"version": "3.1.0",
"private": true
}
In your root package.json
, add the following line to dependencies
:
"dns": "file:./src/mock/dns"
Run npm install
to install the fake dependency, then restart your React project with npm start
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With