vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Uncaught SyntaxError: Cannot use import statement outside a module (at remoteEntry.js:1:1)

Open ivankorobchuk123 opened this issue 2 years ago β€’ 10 comments

I have a paths error.

Uncaught SyntaxError: Cannot use import statement outside a module (at remoteEntry.js:1:1) Screenshot 2022-11-09 at 14 38 13

ivankorobchuk123 avatar Nov 09 '22 14:11 ivankorobchuk123

Try to add type="module" to the script. For example:

<script type="module" src="/src/main.js"></script>

flyfishzy avatar Jan 18 '23 02:01 flyfishzy

Doesn't work for me. I am experiencing the same problem.

The host in my case is a Webpack and the remote is using Vite.

js-lowes avatar Jul 11 '23 17:07 js-lowes

Didn't find a solution. Changed Vite to Webpack

ivankorobchuk123 avatar Jul 11 '23 21:07 ivankorobchuk123

@js-lowes @ivankorobchuk123 did you find a solution?

adirzoari avatar Feb 18 '24 12:02 adirzoari

Sorry, no)

ivankorobchuk123 avatar Feb 18 '24 16:02 ivankorobchuk123

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


Sorry, no)

Issues-translate-bot avatar Feb 18 '24 16:02 Issues-translate-bot

@js-lowes @ivankorobchuk123 did you find a solution?

Unfortunately not, but I have tried vite plugin federation in awhile. Best of luck.

js-lowes avatar Feb 19 '24 00:02 js-lowes

This is pretty straightforward. Your remoteEntry.js from Vite is having import statements which are not allowed in browser unless the script tag has type="module" attribute. Just set the type module on the script tag and it will work fine.

Something like <script type="module" src="http://localhost:3000/assets/remoteEntry.js" />

mjangir avatar Feb 23 '24 10:02 mjangir

@mjangir can you check my similar issue here? https://github.com/originjs/vite-plugin-federation/issues/576

adirzoari avatar Feb 23 '24 10:02 adirzoari