I have a sveltekit app I want to run with payload's express server. I'm doing
import { handler } from "mysvelteproject/handler.js";
const app = express();
....
app.use(handler)
However I get the following error when I build and try to run the server
var handler_js_1 = require("mysvelteproject/handler.js");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Projects/cms/node_modules/mysvelteproject/handler.js from /Projects/cms/dist/server.js not supported.
What I've tried:
Following this post https://discord.com/channels/967097582721572934/1196752494722830376 I changed the tsconfig from "target":"es5" to
"target": "esnext",
"module": "ESNext",
"moduleResolution": "Bundler",
And I changed nodemon.json from using ts-node to tsx "exec": "tsx src/server.ts -- -I"
This almost works. I can do npm run dev and everything runs and works perfectly. However doing npm run build and trying to run the server I get this error now
/Projects/cms/node_modules/payload/dist/config/load.js:28
const configPromise = require(configPath);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Projects/cms/dist/payload.config.js from /Projects/cms/node_modules/payload/dist/config/load.js not supported.
Instead change the require of payload.config.js in /Projects/cms/node_modules/payload/dist/config/load.js to a dynamic import() which is available in all CommonJS modules.
I've also tried all combinations of adding/removing "type":"module" in my svelte and payload project's package.json.
I would really really appreciate any help or guidance here. I've been tearing my head out for the past 3 days with this and I'm out of ideas on what to try.
