Typescript React Component dynamically compiled works in Dev but not production #2564
-
I have a simple typescript page that loads a dynamic MDX string and compiles it and then renders it. This is working and rendering fine on my development machine. But when this is built for production I then get an error failed to fetch dynamically imported module. My code is this
The warning component works and renders correctly in dev but in production it tried to download https://website.com/Components/Warning The compiled code is below and from this I can see why it is trying to download the file. But how do I make it refer to the internal component ?
code
How do I refer to a component definded in the same application? I am using typescript and react and vite |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Welcome @ccrowe-trimble! 👋 await import(_resolveDynamicMdxSpecifier('../Components/Warning')); is a JS dynamic import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import The build tool you are using has not put a file there, so it can't be resolved. |
Beta Was this translation helpful? Give feedback.
-
I have created a simple example showing the following
https://github.com/ccrowe-trimble/mdx I hope this is useful to help me get it to work as I do not know how to make this work in production with dynamic a MDX string. |
Beta Was this translation helpful? Give feedback.
I have come to the realisation that this is probably not going to work how I wanted it to.
Even my simple component still requires React/jsx-runtime to compile and obviosuly my idea was not to have a simple react component but something that probably has lot of dependancies.
Chris