Reputation: 49
Iam having issue with importing MongoDB in production.
I already tried solution from this issue.
Iam getting this error when visiting page with page.server.ts that use DB
Node.js v18.16.1
Error: open EEXIST
at new Socket (node:net:413:13)
at process.getStdin [as stdin] (node:internal/bootstrap/switches/is_main_thread:222:17)
at get (<anonymous>)
at getOwn (node:internal/bootstrap/loaders:190:5)
at BuiltinModule.syncExports (node:internal/bootstrap/loaders:314:31)
at ModuleWrap.<anonymous> (node:internal/bootstrap/loaders:294:17)
at BuiltinModule.getESMFacade (node:internal/bootstrap/loaders:299:17)
at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/loaders:277:10)
at loadBuiltinModule (node:internal/modules/cjs/helpers:56:9)
at Module._load (node:internal/modules/cjs/loader:936:15) {
errno: -17,
code: 'EEXIST',
syscall: 'open'
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
I tried to set everything same as in this repo.
My app starts with node app.cjs
witch contains this:
async function loadApp() {
await import("./index.js");
}
loadApp();
and here is DB.ts
import {MongoClient} from 'mongodb';
import { MONGO_URL } from '$env/static/private';
const client = new MongoClient(MONGO_URL)
export function start_mongo() {
console.log('Starting mongo...');
return client.connect();
}
export default client.db()
I also tried to place it in src/lib/server, src/lib, and src.
Removing import {MongoClient} from 'mongodb';
and page loads just fine.
mongodb is not in devDependencies
Thanks for help!
UPDATE#1
I have also contacted hosting support to see if they can help, and they think the problem is with using async.
"This is the CPU thread issue with Node.js on our server. We suggest you prevent the use of async await
on the code to prevent further errors or breaks on the app."
But removing async did not help.
UPDATE#2
I tried to host my app somewhere else evennode and app works just fine.
Just addding import in any page.server.ts is causing this issue. It seems like just wierd combination of svelte + mongo + my hosting that is causing issue.
Upvotes: 0
Views: 148