Im upgrading from SST 3.2 to 3.11 but as soon as I use the deploy command, I get the following error: Your sst.config.ts has top level imports - this is not allowed. Move imports inside the function they are used and do a dynamic import: const mod = await import("./mod")
This is my old .config file:
import { settings } from 'path/to/settings';
const type = 'test';
export default $config(settings(type));
I have tried to change the config file like this:
const type = 'test';
export default $config(async () => {
const { settings } = await import('path/to/settings');
return settings(type);
});
But I get this error Unexpected error occurred. Please run with --print-logs or check .sst/log/sst.log if available.
with an empty log folder.
I have tried to search for documentation on this but I have not been able to find anything. Has anyone experienced something similar when upgrading?
Im upgrading from SST 3.2 to 3.11 but as soon as I use the deploy command, I get the following error: Your sst.config.ts has top level imports - this is not allowed. Move imports inside the function they are used and do a dynamic import: const mod = await import("./mod")
This is my old .config file:
import { settings } from 'path/to/settings';
const type = 'test';
export default $config(settings(type));
I have tried to change the config file like this:
const type = 'test';
export default $config(async () => {
const { settings } = await import('path/to/settings');
return settings(type);
});
But I get this error Unexpected error occurred. Please run with --print-logs or check .sst/log/sst.log if available.
with an empty log folder.
I have tried to search for documentation on this but I have not been able to find anything. Has anyone experienced something similar when upgrading?
Share Improve this question edited Apr 1 at 3:53 Phil 165k25 gold badges262 silver badges267 bronze badges asked Apr 1 at 3:06 SantamouSantamou 1151 silver badge9 bronze badges 2 |1 Answer
Reset to default 1Have a look at the reference docs for sst.config.ts
.
The $config
function doesn't accept a function, instead it wants an object conforming to the Config
type with app
, run
and console
properties.
Looks like app
is the right callback to use for configuration however what you use depends on the return type of settings()
.
For example...
/// <reference path="./.sst/platform/config.d.ts" />
const type = 'test';
export default $config({
// Your app's config
async app(input) {
const { settings } = await import('path/to/settings');
const { app } = settings(type);
return app(input);
},
// Your app's resources
async run() {
const { settings } = await import('path/to/settings');
const { run } = settings(type);
return run();
},
});
import
is hoisted. Dynamicimport()
is not hoisted. What happens when you do something like thislet fn = async () => { const { settings } = await import('path/to/settings'); return settings(type); }; let result = fn(); export default $config(result);
- that is making sure that dynamicimport()
is executed and there is a result beforeexport
? – guest271314 Commented Apr 1 at 3:24settings()
function return? Can you give an example? – Phil Commented Apr 1 at 3:52