ardatan / ardatan/meteor-webpack

dynamic import at top level fails

Open
#64 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
123
Forks
28
PR merge metrics
No merged PRs in 30d

Description

A)
```
async function main() {
const [
React,
{hydrate},
] = await Promise.all([
import('react'),
import('react-dom'),
]);

hydrate(

asdfasdf
, document.getElementById('root'));
}

main();
```

fails with an error:
```
Uncaught ReferenceError: exports is not defined
at 0.js:1
(anonymous) @ 0.js:1
app.js:817 Uncaught (in promise) Error: Loading chunk 0 failed.
```

If I remove the Promises, it works:
B)
```
import React from 'react';
import {hydrate} from 'react-dom';
hydrate(

asdfasdf
, document.getElementById('root'));
```

Ironically enough, if I replace (B) with (A) now (while meteor is running), the app starts working. It fails again when I restart meteor. Can someone guide me on fixing/debugging this?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce example A in the meteor-webpack project and compare it with example B, including a restart of Meteor to confirm the behavior. Inspect the generated 0.js and app.js around the reported exports error and chunk-loading failure; done means the dynamic import works reliably after restarting Meteor.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.