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

Is it possible to load a sub app using type="module" script tag when the master app doesn't use type="module" script tag #756

Open
hronro opened this issue Jul 14, 2020 · 9 comments

Comments

@hronro
Copy link

hronro commented Jul 14, 2020

Is it possible to load a sub app using type="module script tag when the master app doesn't use type="module script tag?

After some researching I found it seems currently qiankun uses eval to execute scripts of sub apps via import-html-entry module, which means when the javascript context of the master app isn't a module, the javascript context of sub apps can't use module syntax either, which is a big limitation in MICRO FRONTEND architecture.

I wonder if it's possible to use any other ways to executing scripts instead of using eval, e.g. inserting a inline script element to the sub app?

@hronro hronro changed the title Is it possible to load a sub app using type="module script tag when the master app doesn't use type="module script tag Is it possible to load a sub app using type="module" script tag when the master app doesn't use type="module" script tag Jul 14, 2020
@kuitos
Copy link
Member

kuitos commented Jul 14, 2020

Not quite understand what you mean, sorry ~.
Could you pls give a specific case or example to explain your question?

@hronro
Copy link
Author

hronro commented Jul 15, 2020

e.g.

Master app: a regular app created by create-react-app.

Sub app: built without builders, only some static files:

index.html

<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<script type="module" src="/a.js"></script>	
</body>
</html>

a.js

import { foo } from '/b.js';

console.log(foo);

b.js

export const foo = 'Hello World';

@sufengyong
Copy link

@kuitos I have a similar question. I built a Vue3 subapplication using Vite. And the subapplication page has wrote "<script type="module" src="//localhost:3000/main.js" entry></script>"。 But the console keeps reporting errors. "Cannot use Import Statement outside a Module"

@Megan-TA
Copy link

+1

@lalaze
Copy link

lalaze commented Nov 18, 2020

I have same question.Have you solved it?thank :)

@hronro
Copy link
Author

hronro commented Nov 19, 2020

@lalaze Not yet, still waiting for responses from maintainers.

@joker77877
Copy link

It's been almost a year. Haven't you supported it yet.

@otakustay
Copy link

  1. Qiankun loads sub app via import-html-entry
  2. import-html-entry evaluates scripts inside html with new Function
  3. new Function doesn't work like <script type="module">

This is the reason why qiankun is unable to load html with <script type="module"> in it, mostly vite's dev and build assets are not compatible with qiankun.

Fotunately import-html-entry doesn't rely on script's return value, maybe it is possible to implement a more powerful evalCode function to support module behavior.

@Lonli-Lokli
Copy link

So what is the workaround?

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

8 participants