Typescript 3.8 introduced top level await functionality. This is great for me! I enable it by setting the module and moduleResolution settings in tsconfig to ESNext and node respectively.
Suddenly a problem though, my application no longer boots. Instead throwing an error:
SyntaxError: Cannot use import statement outside a module`
Looking over my code I know exactly where its throwing the error, but not sure how to fix it. I've added type:module to my package.json, but still not getting anything to work.
Here is a look at how my boot.ts entry file looks. Under the hood we're starting an express server.
import { Server } from "./api/server";
import {Storage} from "./boot_storage";
import BackedLogger from "./logger/logger";
const storage = new Storage();
storage.boot()
.then(() => {
Server.Instance.startServer(BackedLogger)
});
I know this isn't a ton to go on. I still don't understand imports in Typescript/Node well. I'm more than willing to answer questions and give clarification.
I'm more than willing to change how my application starts in order to get this to work, that's how nice the top level async/await is going to be for me.