sequelize: Error: Please install 'pg' module manually
I’m in the process of switching to Yarnpkg from npm, and i hit this issue. Was working fine before when i was using npm, but using yarn i get this error.
Error: Please install 'pg' module manually
at new ConnectionManager (/home/app/kerberos/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:27:13)
at new PostgresDialect (/home/app/kerberos/node_modules/sequelize/lib/dialects/postgres/index.js:12:28)
at new Sequelize (/home/app/kerberos/node_modules/sequelize/lib/sequelize.js:233:18)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 36 (3 by maintainers)
Links to this issue
Commits related to this issue
- Fix "pg" dialect installation bug. See: https://github.com/sequelize/sequelize/issues/6907. — committed to ferdeleong/genious by ferdeleong 2 years ago
- issues with pg on server, looks like this: https://github.com/sequelize/sequelize/issues/6907 — committed to joelcrawford/market-profile-api by joelcrawford a year ago
Looks like this has to do with where you have the modules installed.
I was running a globally installed
sequelize
, and got this error. When I ran./node_modules/.bin/sequelize
from the node_modules folder it ran fine.So if you’re running
sequelize
from the globally installed node folder, you’ll need to also havepg
installed globallynode v7.2.1, sequelize 3.27.0, pg 6.1.1 returns the same problem when running migrations. Deleted node_modules, reinstalled sequelize and sequelize-cli globally, etc… still stuck with this error. Solved this by installing pg globally (
npm install -g pg
). Is that a new requirement ?a workaround that just works…
webpack.config.js
This issue has been fixed in v5 but is back in v6 😬
I was using webpack and I got it working by following changes:
Looks like this has to do with where you have the modules installed. If you install this globally rather than locally, you can uninstall using the following command:
npm uninstall -g sequalize
Ran into this issue while using NextJS and the
serverless-nextjs-plugin
. The solution for me was the following:Original code with error:
Fix (notice pg import and
dialectModule
specification):The same but without webpack and etc.:
npm install --save-dev noop2
package.json:
Hey coders.
I had this same problem and lost a long time to figure out the solution.
My project is based on lambda serverless from AWS.
In my serverless.yml file i was using serverless-bundle to optimize my package.
After a long time of testing i figured out that this pack need some configurations when using sequelize.
https://www.npmjs.com/package/serverless-bundle#sequelize
About documentation:
To use the Sequelize package along with pg, you’ll need to ignore it from Webpack and using the dialectModule option. Read more here.
In your serverless.yml:
And in your Lambda code:
Wehre pg is your pg module import like:
import pg from "pg";
I hope it helps someone!
Enjoy coding.
This issue can be resolve either by installing
pg
package globally. Or by installingsequelize
andsequelize-cli
packages locally. With local installation you can run sequelize like./node_modules/.bin/sequelize db:migrate
I followed the proposed solutions but didn’t work:
I ended switching to mysql because I even tried the solution that I’m copy/pasting from https://github.com/sequelize/sequelize/issues/9489#issuecomment-493304014 and couldn’t make Postgres to work.
Adding the below code solved my problem
yes i have
Thanks,
npm install -g pg
fixed this issue.I noticed that this is only an issue when i have installed with
yarn --production
or having NODE_ENV=production, so most probably a yarn issue… but still wierd as i have no module devDependencies that i would link to sequelizeI have developed an Express app that is working correctly on my local machine. Now, I am attempting to host it on Vercel, but I am encountering the following error.
When I check the logs, it indicates that there is an issue. " Error: Please install sqlite3 package manually at ConnectionManager._loadDialectModule (/var/task/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:55:15) at new ConnectionManager (/var/task/node_modules/sequelize/lib/dialects/sqlite/connection-manager.js:18:21) at new SqliteDialect (/var/task/node_modules/sequelize/lib/dialects/sqlite/index.js:13:30) at new Sequelize (/var/task/node_modules/sequelize/lib/sequelize.js:194:20) at Object.<anonymous> (/var/task/services/database.js:3:19) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions…js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Ze.e.<computed>._module.Module._load (/var/task/___vc/__launcher/__launcher.js:14:1964) Error: Please install sqlite3 package manually at ConnectionManager._loadDialectModule (/var/task/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:55:15) at new ConnectionManager (/var/task/node_modules/sequelize/lib/dialects/sqlite/connection-manager.js:18:21) at new SqliteDialect (/var/task/node_modules/sequelize/lib/dialects/sqlite/index.js:13:30) at new Sequelize (/var/task/node_modules/sequelize/lib/sequelize.js:194:20) at Object.<anonymous> (/var/task/services/database.js:3:19) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions…js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Ze.e.<computed>._module.Module._load (/var/task/___vc/__launcher/__launcher.js:14:1964) Error: Runtime exited with error: exit status 1 Runtime.ExitError
" I think i have installed sqlite3 already as i am using the following package.json file package.json file " { “name”: “funrun4”, “version”: “0.0.0”, “private”: true, “main”: “/index.js”, “engines”: { “node”: “18.x” }, “scripts”: { “start”: “node ./bin/www”, “dev”: “nodemon ./bin/www -e js,ejs,html,css” }, “dependencies”: { “app-module-path”: “^2.2.0”, “cookie-parser”: “~1.4.4”, “debug”: “~2.6.9”, “dotenv”: “^16.3.1”, “ejs”: “^3.1.9”, “express”: “^4.18.2”, “http-errors”: “~1.6.3”, “morgan”: “~1.9.1”, “sequelize”: “^6.33.0”, “sqlite3”: “^5.1.6” }, “devDependencies”: { “nodemon”: “^3.0.1” } }
"
I am not sure how to resolve this problem. Please provide guidance on how to correct it.
I found a fix that worked for me! If you have webpack configured it might help. First, install webpack-node-externals
yarn add -D webpack-node-externals
then in your webpack require it
const nodeExternals = require('webpack-node-externals')
and finally in your config :
externals: [nodeExternals()]
@leolio86400 I found it in the source code: https://github.com/sequelize/sequelize/blob/d06aa0327a3c4f5dfbe9a563813d1ff1e7fec41c/src/sequelize.js#L132
You can also find it in the API reference section under
public constructor
: https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html