-
SummaryA strategy I've used to great success before under Express was to use When trying to do this under Next.js, it gives me an error for the import with this text: It seems like they have special-cased an error for this import to stop people from accidentally doing something incorrect with server components, but in this case I'm not working with server components at all and I really do need to use renderToString and not something else. Any ideas how I could suppress this error message and gain access to the Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
After significant investigation I've found a viable workaround. Firstly, there doesn't seem to be any way around this restriction as it's implemented both in a Webpack plugin (which can be disabled) and in Next.js's Rust-based React Server Components transformer (which can't be disabled). Using a I also tried using Preact as an alternative to render my HTML, but it doesn't appear to be possible to use both React and Preact in the same project. The solution which did work for me is to asynchronously import the To be frank this situation is ridiculous and reflects poorly on Next.js as a framework. The bare minimum we should expect from our tools is not to break things which were already working. |
Beta Was this translation helpful? Give feedback.
-
|
I needed this to render some html for microdata and had to use dynamic import hack as well... |
Beta Was this translation helpful? Give feedback.
After significant investigation I've found a viable workaround.
Firstly, there doesn't seem to be any way around this restriction as it's implemented both in a Webpack plugin (which can be disabled) and in Next.js's Rust-based React Server Components transformer (which can't be disabled).
Using a
requirestatement instead ofimportworked from within Next.js, but I was no longer able to execute this same code directly from Node.js which in this case I needed to do.I also tried using Preact as an alternative to render my HTML, but it doesn't appear to be possible to use both React and Preact in the same project.
The solution which did work for me is to asynchronously import the
react-dom/…