Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build error: ModuleNotFoundError: Module not found: Error: Can't resolve 'pg-native' #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

FinnWoelm
Copy link

This PR fixes the build for serverless NextJS on Netlify by excluding pg-native from being bundled.

Full explanation here: netlify/next-on-netlify#33

The PR has lots of working commits. Feel free to squash and merge.

For reference, this is the error that this PR fixes:

info  - Creating an optimized production build  
Failed to compile.

ModuleNotFoundError: Module not found: Error: Can't resolve 'pg-native' in '/home/fwoelm/Projects/broken-sequelize-netlify/node_modules/pg/lib/native'


> Build error occurred

According to the Getting Started page of Sequelize, pg-hstore is
required for Postgres:
https://sequelize.org/master/manual/getting-started.html
sequelize requires ./native file which depends on pg-native. To pack
sequelize with webpack, we need to ignore this import by adding it to
the list of ignored plugins in next.config.js

See:
sequelize/sequelize#3781 (comment)
Configure netlify.toml for next-on-netlify.
Test if we can skip this step and still succeed with build and 
deployment.
Manually install pg-native for SSL support.
This reverts commit b157885.

Installing pg-native fails on netlify due to node-libpq.

Seems to be a known issue:
- https://community.netlify.com/t/unable-to-publish-function-using-postgres/12293/3
- netlify/build-image#393
There were some remarks about console.logs causing issues with 
pg-native, so I temporarily commented-out the console.logs. Anyway, 
these console.logs do not seem to be an issue.

See: 
sequelize/sequelize#3781 (comment)
Improve documentation for webpack settings in next.config.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant