react-rails icon indicating copy to clipboard operation
react-rails copied to clipboard

Dynamic imports `import()` results in error (SSR)

Open dachinat opened this issue 6 years ago • 4 comments

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:

screen shot 2019-02-13 at 6 55 05 am

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.

dachinat avatar Feb 13 '19 02:02 dachinat

did you ever solve this @dachinat?

noisyscanner avatar Jul 02 '19 18:07 noisyscanner

@noisyscanner No sadly

dachinat avatar Jul 03 '19 17:07 dachinat

@noisyscanner @dachinat Do you need this for any specific reason? You can split your code using SplitChunksPlugin and that allows SSR to work properly.

BookOfGreg avatar Jul 04 '19 21:07 BookOfGreg

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

BookOfGreg avatar Jul 04 '19 21:07 BookOfGreg

It is marked as invalid, so closing this issue.

alkesh26 avatar Nov 04 '22 06:11 alkesh26