I imported mongodb with import { MongoClient } from 'mongodb';
, (version of mongodb is 4.0.0-beta.5) it works fine in svelte-kit dev
and svelte-kit preview
, but when I try to start the server with node build
, it throws Error: Dynamic require of "os" is not supported
. How can I configure sveltekit or vite to import mongodb in production?
Asked
Active
Viewed 1,699 times
3

Si-Wei Yang
- 321
- 5
- 11
-
That comment u added solved it? dont forget to mark as answered ;) - otherwise share you nodejs version. – Sagive Jul 14 '21 at 23:40
1 Answers
4
I found that since vite only precompiles packages in dependencies (https://github.com/vitejs/vite/issues/162#issuecomment-629623566), mongodb should be in dependencies, not devDependencies.

Si-Wei Yang
- 321
- 5
- 11