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

V7 unexpected sqlite error when using PM2 #3899

Closed
xconverge opened this issue Nov 28, 2024 · 1 comment · Fixed by #3900
Closed

V7 unexpected sqlite error when using PM2 #3899

xconverge opened this issue Nov 28, 2024 · 1 comment · Fixed by #3900
Labels
bug Something isn't working

Comments

@xconverge
Copy link
Contributor

xconverge commented Nov 28, 2024

Bug Description

I am using pm2 for managing my application and something about the expermental node:sqlite detection doesn't work correctly/is incompatible.

Reproducible By

test.js:

const { fetch } = require("undici");
console.log("hello");

This works fine of course:

node test.js

This does not:

pm2 start test.js

and errors with this

pm2 logs
Error: Cannot find module 'node:sqlite'
Require stack:
- /path/src/archive/test/node_modules/undici/lib/cache/sqlite-cache-store.js
- /path/src/archive/test/node_modules/undici/index.js
- /path/src/archive/test/test.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Hook._require.Module.require (/path/.local/share/nvm/v22.11.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:81:25)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/path/src/archive/test/node_modules/undici/lib/cache/sqlite-cache-store.js:3:26)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/path/src/archive/test/node_modules/undici/lib/cache/sqlite-cache-store.js',
    '/path/src/archive/test/node_modules/undici/index.js',
    '/path/src/archive/test/test.js'
  ]
}

I can get around it by explicitly setting the flag like this

pm2 start test.js --node-args="--experimental-sqlite"

Expected Behavior

node:sqlite is detected correctly (as missing or not) when running through pm2

Logs & Screenshots

Environment

Node v22
Undici v7.0.0

Additional context

@xconverge xconverge added the bug Something isn't working label Nov 28, 2024
@xconverge xconverge changed the title Node v22 undici v7 unexpected sqlite error when using PM2 V7 unexpected sqlite error when using PM2 Nov 28, 2024
@xconverge
Copy link
Contributor Author

Not sure if there is something deeper or more complex I am missing but this fixes it I believe, just makes the check a little less strict to prevent catastrophic failure

diff --git a/index.js b/index.js
index 77c0bfde..32537137 100644
--- a/index.js
+++ b/index.js
@@ -53,7 +53,7 @@ try {
   const SqliteCacheStore = require('./lib/cache/sqlite-cache-store')
   module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore
 } catch (err) {
-  if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') {
+  if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE' && err.code !== 'MODULE_NOT_FOUND') {
     throw err
   }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant