1. {
    2. const mainAwait = () => {
    3. return new Promise((resolve, reject) => {
    4. setTimeout(() => {
    5. resolve(100)
    6. }, 500)
    7. })
    8. }
    9. const output = await mainAwait()
    10. console.log(output) // 100
    11. setTimeout(() => console.log(output, 1000)) // 1000
    12. // TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
    13. // 仅当文件是模块时,才允许在该文件的顶层使用 "await" 表达式,但此文件没有导入或导出。请考虑添加空的 "export {}" 以将此文件变为模块。
    14. }
    15. export { }

    注:仅当文件是模块时,才允许顶层使用 “await” 表达式
    解决方法使用 “ import { mainAwait } from ‘./utils/index’ “ 或者 “export {}” 以将此文件变为模块
    image.png