How to import utility module in a vite project #160
-
So, I have two TLDR;I tried creating utility module using both:
First option gave me this error
When I try to add the same utility module into projects created using Can you guide us how can we achieve utility modules functionality with vite-plugin-single-spa ? Longer VersionSo, my root project's files looks like this
Entry point file
I get this error,
If you made it this far, I truly appreciate your efforts 🙇🏻♂️. Thanks for it. Your help is really appreciated ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If "@kd/utility" is meant to be externally provided, you must set the rollup options to include this module as external. Note, however, that this only applies to bundling. When running the project in serve mode (
To summarize: You need to learn about externals in Vite. Once you learn about the topic, you'll be able to understand why this happens and how to solve it. Hopefully with what I explained you'll be able to investigate and solve. Good luck! |
Beta Was this translation helpful? Give feedback.
-
Thanks @webJose for the quick reply 🙇 Understood how externals work in Vite and, as you suggested, implemented The main thing is, if all the configurations are done correctly, things are working perfectly but since Vite does not recognise external dependencies in runtime ( Here's what I didI added vite-plugin-externalize-dependencies in my project. So, my
Utility's config
Updated
And it's usage
And things worked 🥹 Thanks @webJose for all the help ❤️ |
Beta Was this translation helpful? Give feedback.
Thanks @webJose for the quick reply 🙇
Understood how externals work in Vite and, as you suggested, implemented
vite-plugin-externalize-dependencies
to suppress the dependency errors.The main thing is, if all the configurations are done correctly, things are working perfectly but since Vite does not recognise external dependencies in runtime (
npm run dev
) the App won't come up due to that error. Hence, suppressing the error makes it work!!Here's what I did
I added vite-plugin-externalize-dependencies in my project. So, my
vite.config.js
(for the MiFe where I want to add the utility) looks like this now