content icon indicating copy to clipboard operation
content copied to clipboard

dependency pg in production + refresh page error

Open giticon opened this issue 10 months ago • 8 comments

Environment

  • Operating System: windows 11 pro
  • Node Version: v22.13
  • Nuxt Version: 3.15.4
  • Nitro Version: 2.10.4 Server: Vercel
  • Package Manager: Yarn v1.22.19 package:
package: -
    "dependencies": {
    "@nuxt/content": "^3.0.1",
    "@nuxt/fonts": "^0.10.3",
    "@nuxt/ui": "2.21.0",
    "@nuxtjs/seo": "^2.0.2",
    "nuxt": "^3.15.4",
    "pg": "^8.13.1",
    "sass": "^1.82.0",
    "vue": "latest",
    "vue-router": "latest"
  },
  "devDependencies": {
    "@nuxt/image": "^1.8.1",
    "nuxt-svgo": "^4.0.9"
  }

Version

v3

Reproduction

.

Description

In developer mode I don't have any problems.

However, when I go to production the deployment fails because it tells me that the "pg" dependency is missing.

Installing pg bypasses the problem but the deployment still fails again due to a different error

[nuxt] [request error] [unhandled] [500] connect ECONNREFUSED 127.0.0.1:5432

The point is that if I navigate between the pages the data (markdown + yaml) is displayed correctly in the pages, while if I refresh the data is not loaded.

I have tried the various solutions proposed such as updating the packages and reinstalling node_modules from scratch but the problem persists.

Here are some additional details that might be useful:

  • The error message "connect ECONNREFUSED 127.0.0.1:5432" indicates that the application is trying to connect to a PostgreSQL database on the local machine (127.0.0.1) on port 5432, but the connection is being refused. Nuxt/content uses the default configuration (sqlite). I have also tried to specify in config that it is sqlite but nothing, it does not work: it always gives me the same error.

Additional context

No response

Logs


giticon avatar Feb 03 '25 11:02 giticon

In order to deploy on Vercel, Content module requires a small database to store/retrieve contents in performant way. In Vercel it is not possible yet to create local sqlite database. However there is some database providers that offer free tier to use with Nuxt Content.

For example you can try integrate Neon database to your project. Once you integrate it with your project, just redeploy. Module will automatically detect the database using Vercel's environment variables.

farnabaz avatar Feb 03 '25 11:02 farnabaz

I understand. Thank you for your response. I suspected it was something like that.

The strange thing is that I have another site with this configuration


"devDependencies": {
    "@pinia/nuxt": "0.9.0",
    "nuxt": "^3.15.1",
    "nuxt-svgo": "^4.0.9",
    "pinia": "^2.3.0"
  },
  "dependencies": {
    "@nuxt/content": "^3.0.0",
    "@nuxt/image": "^1.8.1",
    "@nuxt/ui": "^2.20.0",
    "@nuxtjs/sitemap": "^7.2.2",
    "@vueuse/nuxt": "^12.2.0",
    "gsap": "^3.12.5",
    "lite-vimeo-embed": "^0.3.0",
    "lite-youtube-embed": "^0.3.3",
    "nuxt-swiper": "^1.2.2",
    "pg": "^8.13.1",
    "sass": "^1.83.0",
    "vanilla-lazyload": "^19.1.3"
  }

That on Vercel works perfectly without an external db. They are slightly older packages. The server configuration is the same. How come?

Another question: for nuxt which other servers already have a local sqlite db?

giticon avatar Feb 03 '25 12:02 giticon

I configured the db within Vercel/Storage. I confirm that with NeonDB it works perfectly without modifying anything.

giticon avatar Feb 03 '25 13:02 giticon

Hi @farnabaz,

Somehow that's not working for me... I created a neon DB on Vercel and added my project to it. I try to redeploy it, but without success.

Image Image Image

Any idea?

Update I assume it has to do with my previews. I'm working on a V2 branch and now see the Postgres Previews Integration

stijns96 avatar Feb 09 '25 19:02 stijns96

@stijns96 try npm install pg

giticon avatar Feb 09 '25 20:02 giticon

@stijns96 try npm install pg

Did that work for you?

Update That worked, thank! Not sure about Neon tho... Even the preview integration didn't worked for me.

stijns96 avatar Feb 09 '25 20:02 stijns96

it worked, without doing anything. the preview also works. Try deleting nodex_modules and .lock and reinstalling the updated packages

giticon avatar Feb 09 '25 21:02 giticon

The good news is starting the next release (planned for today), the module does not force you to use third-party database and uses an internal SQLite database.

Original commit: https://github.com/nuxt/content/issues/3050#issuecomment-2643444193

farnabaz avatar Feb 10 '25 12:02 farnabaz