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

[v3] Not possible to use with PG database #3104

Closed
maxdzin opened this issue Feb 6, 2025 · 7 comments
Closed

[v3] Not possible to use with PG database #3104

maxdzin opened this issue Feb 6, 2025 · 7 comments

Comments

@maxdzin
Copy link

maxdzin commented Feb 6, 2025

Environment

  • Operating System: Linux
  • Node Version: v22.13.1
  • Nuxt Version: 3.15.4
  • CLI Version: 3.21.1
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, devtools, compatibilityDate, future, content
  • Runtime Modules: @nuxt/[email protected]
  • Build Modules: -

Version

v3

Reproduction

https://github.com/maxdzin/nuxt-content-issue

Description

Starting from v3.1.0 it is impossible to use the module that configured to use the Postgres DB, because of the error (requirement of sqlite3).

Steps to reproduce:

  1. Checkout the reproducion repository.
  2. Set DATABASE_URL to point to the Postgres database.
  3. By installing dependencies (pnpm install) it is failed with this error:
ERROR  Nuxt Content requires sqlite3 module to work in WebContainer environment. Please run npm install sqlite3 to install it and try again.

 ELIFECYCLE  Command failed with exit code 1.

Additional context

There's also another project where I was trying to use the content module with PG DB, but it failed due to errors (see the logs section).

Logs

ERROR  Cannot start nuxt:  Could not locate the bindings file. Tried:
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Release/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Debug/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Release/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Release/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/default/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/compiled/22.13.1/linux/x64/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/release/install-root/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/debug/install-root/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/default/install-root/better_sqlite3.node
 → /.../nuxt-content-issue/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/binding/node-v127-linux-x64/better_sqlite3.node

    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Release/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Debug/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Release/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Release/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/default/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/compiled/22.13.1/linux/x64/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/release/install-root/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/debug/install-root/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/default/install-root/better_sqlite3.node
    → node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/binding/node-v127-linux-x64/better_sqlite3.node
    at bindings (node_modules/.pnpm/[email protected]/node_modules/bindings/bindings.js:126:9)
    at new Database (node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:48:64)
    at getDB (node_modules/.pnpm/[email protected][email protected]/node_modules/db0/connectors/better-sqlite3.mjs:19:11)
    at Object.exec (node_modules/.pnpm/[email protected][email protected]/node_modules/db0/connectors/better-sqlite3.mjs:27:14)
    at getLocalDatabase (node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@nuxt/content/dist/module.mjs:338:12)
    at async processCollectionItems (node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@nuxt/content/dist/module.mjs:2379:14)
    at async node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@nuxt/content/dist/module.mjs:2355:20
    at async initNuxt (node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected]_b_e8de5c6466f45d28f9535e769d589061/node_modules/nuxt/dist/shared/nuxt.CrJjphBv.mjs:5343:3)
    at async NuxtDevServer._load (node_modules/.pnpm/@[email protected][email protected]/node_modules/@nuxt/cli/dist/chunks/dev2.mjs:161:5)
    at async NuxtDevServer.load (node_modules/.pnpm/@[email protected][email protected]/node_modules/@nuxt/cli/dist/chunks/dev2.mjs:93:7)
@maxdzin maxdzin changed the title [v3] [v3] Not possible to use with PG database Feb 6, 2025
@hdwebpros
Copy link

Might be related to this: #3050

@maxdzin
Copy link
Author

maxdzin commented Feb 6, 2025

@hdwebpros it seems a different thing (but, yes, it could be somehow related) since it was possible at least to install the module and launch it locally before the v3.1.0, but it is not possible even to launch the project after that release.

@farnabaz
Copy link
Member

farnabaz commented Feb 7, 2025

The module always uses SQLite database in local and development mode, the database will be used in production. So depending on where you want to deploy, you choose the database.

By installing dependencies (pnpm install) it is failed with this error:
ERROR Nuxt Content requires sqlite3 module to work in WebContainer environment. Please run npm install sqlite3 to install it and try again.

Do you face this error in Linux or inside WebContainers, like Stackblitz? Have you tried installing sqlite3 package as the error suggests, to see if it's working?

I just cloned the reproduction, and it does work as expected.

@maxdzin
Copy link
Author

maxdzin commented Feb 7, 2025

@farnabaz Thank you for checking.

The module always uses SQLite database in local and development mode

That sounds strange. Why sqlite3 is required while it was configured to use postgres?

Do you face this error in Linux or inside WebContainers, like Stackblitz?

Tried both, Linux locally and in Stackblitz.

Have you tried installing sqlite3 package as the error suggests, to see if it's working?

Of course, I tried to install sqlite3, but when I launched the project (ppm run dev), it just showed the errors I mentioned in the "Logs" section above.

Before v3.1.0 it was working well (I tried v3.0.0 and v3.0.1).

Feel free to ask for some additional info. I woud be glad to share.

@farnabaz
Copy link
Member

farnabaz commented Feb 7, 2025

I just tried your reproduction in Stackblitz with sqlite3 package. check out https://stackblitz.com/edit/github-t4utbhhu?file=package.json\

Tried both, Linux locally and in Stackblitz.

I Linuxt you should not face sqlite3 issue 🤔 We are checking strictly for web containers

function isSqlite3Available() {
if (!isWebContainer()) {
return false
}
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('sqlite3')
return true
}
catch {
logger.error('Nuxt Content requires `sqlite3` module to work in WebContainer environment. Please run `npm install sqlite3` to install it and try again.')
process.exit(1)
}
}

Maybe the check is buggy in linux

@maxdzin
Copy link
Author

maxdzin commented Feb 7, 2025

@farnabaz
I'm sorry, I should express myself clearer.

That WebContainer error indeed dropped when I tried in Stackblitz, while the errors I include in "Logs" are in Local environment.

But why is that sqlite3 needs to be installed while using postgres? What is the reason?

@maxdzin
Copy link
Author

maxdzin commented Feb 11, 2025

OK, I found out the problem. It was related to this issue: pnpm/pnpm#9073
When using pnpm > v10 it needs approve-builds to make all dependencies installed and built properly. With [email protected] it is at least verbose now and pointing such a warning during pnpm istall script:

╭ Warning ──────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                   │
│   Ignored build scripts: @parcel/watcher, better-sqlite3, esbuild.                                │
│   Run "pnpm approve-builds" to pick which dependencies should be allowed to run scripts.          │
│                                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯

So, after approving builds it works properly now.

@maxdzin maxdzin closed this as completed Feb 11, 2025
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

No branches or pull requests

3 participants