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

dynamic import at top level fails #64

Open
s7dhansh opened this issue Apr 2, 2019 · 5 comments
Open

dynamic import at top level fails #64

s7dhansh opened this issue Apr 2, 2019 · 5 comments

Comments

@s7dhansh
Copy link
Contributor

s7dhansh commented Apr 2, 2019

A)

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

	hydrate(<div>asdfasdf</div>, 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(<div>asdfasdf</div>, 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?

@abecks
Copy link
Collaborator

abecks commented Apr 2, 2019

I don't believe Meteor's dynamic import functionality will currently work with this package. Some more work is likely required. You might be better off using webpack's code splitting functionality.

@s7dhansh
Copy link
Contributor Author

s7dhansh commented Apr 2, 2019

How do I do that?
Webpack's code splitting with dynamic imports also uses the same syntax, right? Should I remove dynamic-import from meteor packages?

@abecks
Copy link
Collaborator

abecks commented Apr 2, 2019 via email

@ardatan
Copy link
Owner

ardatan commented Apr 3, 2019

@s7dhansh @abecks Meteor-Webpack supports dynamic imports by serving chunks as assets;

I think there is a problem in dev-middleware package about calculation of output files.
68898dc#diff-8f10efed2c00dab752c268b55cfd62a1
The problem may be related to this commit, on each compilation the assets to be served must be recalculated.

@s7dhansh
Copy link
Contributor Author

s7dhansh commented Apr 3, 2019

@ardatan sorry I have very limited understanding of what you are saying. Can you let me know a fix that I can try?

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

No branches or pull requests

3 participants