Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top-level await does not wait for its dependencies #2473

Open
qingwabote opened this issue Nov 26, 2023 · 0 comments
Open

Top-level await does not wait for its dependencies #2473

qingwabote opened this issue Nov 26, 2023 · 0 comments
Labels

Comments

@qingwabote
Copy link

Demonstration

a.ts

let a:string;

async function delay():Promise<void> {
    return new Promise(function(resolve){
        setTimeout(() => {
            resolve();
        }, 1000);
    })
}

await delay();

a = 'a';

export {a};

b.ts

import {a} from './a.js'

console.log('a in b',a)

c.ts

import {a} from './a.js'

console.log('a in c',a)

index.ts

export * from './a.js'
export * from './b.js'
export * from './c.js'

index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
</head>

<body>
  <script src="./dist/s.js"></script>
  <script type="systemjs-module" src="./dist/index.js"></script>
</body>

</html>

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2017", 
    "module": "System", 
    "moduleResolution": "node", 
    "allowJs": true, 
    "sourceMap": false, 
    "outDir": "dist", 
    "esModuleInterop": true, 
    "forceConsistentCasingInFileNames": true, 
    "strict": true,
    "skipLibCheck": true 
  }
}

tsc them to systemjs module and run web server

Expected Behavior

two logs without error after 1000ms

Actual Behavior

b.js:12 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'a')
at Object.execute (b.js:12:37)
at doExec (s.js:429:40)
at postOrderExec (s.js:426:16)
at s.js:415:38
at Array.forEach ()
at postOrderExec (s.js:413:16)
at s.js:381:20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants