When you initiate the payload cms project you get Target ES5, this does not support top level await.
I tried changing it to ES2022, ES2017, with module : ES2017 and moduleResolution : node and all sorts of combinations but the builds either fail or it crashes when you run it because of bad imports.
Has anybody here had any luck with changing the ts config to go beyond es5?
By the way the Use case is this:
Loading credentials from AWS SSM
Hey
@276227047968210945I responded to your issue on GitHub, and I'd certainly be interested in tracking down any incompatible packages that Payload relies on to be able to run ESM
to get around top-level await, for now, you could always just wrap your server code in a function and then call it
import express from 'express';
import payload from 'payload';
require('dotenv').config();
const app = express();
// Redirect root to Admin panel
app.get('/', (_, res) => {
res.redirect('/admin');
});
const start = async () => {
// Fetch your secrets
await fetchSecrets()
// Initialize Payload
await payload.initAsync({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
},
})
// Add your own express routes here
app.listen(3000);
}
start()
would something like that be a stop-gap solution for you?
still though, it seems like we shouldn't need to support ESM to support a higher target than es5
and even still, i'd expect that TS should be able to transpile top-level await to es5 anyway
there's certainly more reading / thinking to be done here
Yes I am doing this rn
But TOp level is cleaner
I have the same question 🙂
Would love to hear what the plans are around this
I assume that once payload switches from CJS to ESM, everything will be better and we can have top level await
Is this still the case? I was trying to follow the [example for creating a seeding script in Node](
https://payloadcms.com/docs/local-api/outside-nextjs#importing-the-payload-config-outside-of-nextjs) and got this error :
Top-level await is currently not supported with the "cjs" output format
Also tried
bun payload run seed.ts
but got same error
This is supported, you just need to enable esm in your project. To do that, add "type": "module" to your package.json
Star
Discord
online
Get dedicated engineering support directly from the Payload team.