Dynamic imports `import()` results in error (SSR)
Expected behavior
It should server-side render an App and dynamically import jsx/js
Actual behavior
It tells that window is not defined
System configuration
Sprockets or Webpacker version: Webpacker React-Rails version: 2.4.7 React_UJS version: 2.4.4 Rails version: 6.0.0.beta.1 Ruby version: 2.6.0
Hello.
If I use dynamic import import() in my code, then it will show an error message.
I have tried using therubyracer, mini_racer and standard macOS tool.
Screenshot is below:
My server_rendering.js is standard:
import React, { Component } from 'react';
// import('./Test');
export default () => <div>hello</div>;
P.S. This happens when you prerender for ssr.
did you ever solve this @dachinat?
@noisyscanner No sadly
@noisyscanner @dachinat Do you need this for any specific reason? You can split your code using SplitChunksPlugin and that allows SSR to work properly.
Also discovered this thread on Webpack itself, looks like it's an upstream issue so marking this as invalid: https://github.com/webpack/webpack/issues/4199
It is marked as invalid, so closing this issue.