简体   繁体   中英

Redux-Observable breaks on server-side rendering

I have a test repo with redux-observable

It works with webpack-dev-server but breaks with server-side-rendering giving:

TypeError: action$.ofType(...).delay is not a function

How to reproduce:

yarn dev works okay (webpack-dev-server).

yarn build && yarn start - runs node server-side-rendering which is breaking when creating store with redux createStore method.

It recognizes imported operators from rxjs within a browser (webpack-dev-server). My guess it might be a problem with webpack serverConfig , more specifically with:

  externals: fs.readdirSync('./node_modules').concat([
    'react-dom/server',
  ]).reduce((ext, mod) => {
    ext[mod] = `commonjs ${mod}`;
    return ext;
  }, {}),

importing the whole rxjs library will jeopardise your tree shaking.

use pipe instead.

import { delay } from 'rxjs/operators';

const epic = action$ => action$
  .ofType('baz')
  .pipe(delay(5000))
  .mapTo({ type: 'bar' });
;

It turned out I had to include rxjs in server.js where express is like:

import `rxjs`;

But I would swear I tried that solution before I posting a question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM