N
Nuxt3mo ago
bunomel

Nuxt-Content better-sqlite3

I have a problem, where my content does not show up on initial page load, only when routing to a page where through nuxtlink. I think PM2 is running fine. But the logs are here:

0|MYAPP | [request error] [unhandled] [POST] http://localhost/__nuxt_content/services/query?v=v3.5.0--6T1Wqm2ZjMYZHm_X0K2vQCrrEz7Uz47n4DF65uDJXf4
0|MYAPP | H3Error: /home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/build/Release/better_sqlite3.node: invalid ELF header
0|MYAPP | at Object..node (node:internal/modules/cjs/loader:1921:18)
0|MYAPP | ... 8 lines matching cause stack trace ...
0|MYAPP | at new Database (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/lib/database.js:48:64) {
0|MYAPP | cause: Error: /home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/build/Release/better_sqlite3.node: invalid ELF header
0|MYAPP | at Object..node (node:internal/modules/cjs/loader:1921:18)
0|MYAPP | at Module.load (node:internal/modules/cjs/loader:1465:32)
0|MYAPP | at Function._load (node:internal/modules/cjs/loader:1282:12)
0|MYAPP | at TracingChannel.traceSync (node:diagnostics_channel:322:14)
0|MYAPP | at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
0|MYAPP | at Module.<anonymous> (node:internal/modules/cjs/loader:1487:12)
0|MYAPP | at Module.Hook._require.Module.require (/home/mytestapp/.nvm/versions/node/v22.16.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
0|MYAPP | at require (node:internal/modules/helpers:135:16)
0|MYAPP | at bindings (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/bindings/bindings.js:112:48)
0|MYAPP | at new Database (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/lib/database.js:48:64) {
0|MYAPP | code: 'ERR_DLOPEN_FAILED'
0|MYAPP | },
0|MYAPP | statusCode: 500,
0|MYAPP | fatal: false,
0|MYAPP | unhandled: true,
0|MYAPP | statusMessage: undefined,
0|MYAPP | data: undefined
0|MYAPP | }

0|MYAPP | [request error] [unhandled] [POST] http://localhost/__nuxt_content/services/query?v=v3.5.0--6T1Wqm2ZjMYZHm_X0K2vQCrrEz7Uz47n4DF65uDJXf4
0|MYAPP | H3Error: /home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/build/Release/better_sqlite3.node: invalid ELF header
0|MYAPP | at Object..node (node:internal/modules/cjs/loader:1921:18)
0|MYAPP | ... 8 lines matching cause stack trace ...
0|MYAPP | at new Database (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/lib/database.js:48:64) {
0|MYAPP | cause: Error: /home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/build/Release/better_sqlite3.node: invalid ELF header
0|MYAPP | at Object..node (node:internal/modules/cjs/loader:1921:18)
0|MYAPP | at Module.load (node:internal/modules/cjs/loader:1465:32)
0|MYAPP | at Function._load (node:internal/modules/cjs/loader:1282:12)
0|MYAPP | at TracingChannel.traceSync (node:diagnostics_channel:322:14)
0|MYAPP | at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
0|MYAPP | at Module.<anonymous> (node:internal/modules/cjs/loader:1487:12)
0|MYAPP | at Module.Hook._require.Module.require (/home/mytestapp/.nvm/versions/node/v22.16.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
0|MYAPP | at require (node:internal/modules/helpers:135:16)
0|MYAPP | at bindings (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/bindings/bindings.js:112:48)
0|MYAPP | at new Database (/home/mytestapp/htdocs/mytestapp.mydomain.com/.output/server/node_modules/better-sqlite3/lib/database.js:48:64) {
0|MYAPP | code: 'ERR_DLOPEN_FAILED'
0|MYAPP | },
0|MYAPP | statusCode: 500,
0|MYAPP | fatal: false,
0|MYAPP | unhandled: true,
0|MYAPP | statusMessage: undefined,
0|MYAPP | data: undefined
0|MYAPP | }
i am using the preset: 'node-server' in the nuxt condig.
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @bunomel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Your error message:
H3Error: .../better_sqlite3.node: invalid ELF header
H3Error: .../better_sqlite3.node: invalid ELF header
indicates that the better-sqlite3 native module is not compatible with your current environment. This usually happens when the better-sqlite3 binary was built on a different OS or architecture than the one you're running your app on, or if you copied node_modules from a different machine or Node.js version. Key points from the Nuxt Content documentation: - If you are using the default better-sqlite3 module, you must deploy to an OS with Glibc version higher than 2.29 (e.g., Debian 11, Ubuntu 20.04). You can check your Glibc version with ldd --version Server Hosting. - The SQLite database is loaded on the server side when booting the server. If the native module is broken, content queries will fail. - If you are running Node.js v22.5.0 or above, you can enable the native SQLite driver and avoid better-sqlite3 entirely by setting the following in your nuxt.config.ts:
export default defineNuxtConfig({
content: {
experimental: { nativeSqlite: true },
},
})

export default defineNuxtConfig({
content: {
experimental: { nativeSqlite: true },
},
})

This uses Node.js's built-in SQLite support and does not require better-sqlite3 experimental.nativeSqlite. How to fix: 1. Rebuild better-sqlite3:
Delete your node_modules and lockfile, then reinstall dependencies on the target server:
rm -rf node_modules package-lock.json pnpm-lock.yaml yarn.lock
npm install

rm -rf node_modules package-lock.json pnpm-lock.yaml yarn.lock
npm install

This ensures better-sqlite3 is built for the correct environment. 2. Use native SQLite (Node.js ≥ 22.5.0):
If you are on Node.js v22.5.0 or newer, enable the native driver as shown above. 3. Check your OS compatibility:
Make sure your server OS meets the Glibc requirement. Summary:
The "invalid ELF header" error is a native module compatibility issue. Rebuild your dependencies on the deployment server, or use the new native SQLite support if your Node.js version allows it Server Hosting experimental.nativeSqlite. If you continue to have issues, double-check your deployment process to ensure no node_modules are copied from a different environment. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@238313447169720321> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
bunomel
bunomelOP3mo ago
I want to add. It is build on a different machine. my Glibc is compatible ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39 as i wrote before, it works after navigating As always the Problem is behind the keyboard. I builded for node v20 but deployed to node v22 So my bad

Did you find this page helpful?