Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falcor doesn't make requests when bundled with webpack #338

Closed
memoryhole opened this issue Jul 22, 2015 · 9 comments
Closed

Falcor doesn't make requests when bundled with webpack #338

memoryhole opened this issue Jul 22, 2015 · 9 comments
Assignees
Labels

Comments

@memoryhole
Copy link

I'm looking at migrating a project from browserify to webpack. When I do so Falcor stops making network requests.

@sdesai mentioned he's seen a similar problem and suspected it was due to a duplicate Rx dependency in the bundle. I've tried adding the dedupe plugin and using resolve.alias directives in webpack, but the issue persists.

@sdesai
Copy link
Contributor

sdesai commented Jul 22, 2015

Model also seems to be included twice (and I imagine other modules also, based on how they are required). I also played with npm dedupe, resolve.alias with no luck.

Webpack doesn't seem to do as thorough a job of removing duplicate modules [ with diff. absolute require paths ] as Browserify, hence the issue.

I imagine it's some module state [ probably with Rx, and the way it has modules which modify the 'global' Rx export prototype ], which gets clobbered when the base Rx module is required a second time. Where I left it, it wasn't able to find the 'reduce' operator while trying to dispatch the request [ and the error was being swallowed ]

@sdesai
Copy link
Contributor

sdesai commented Jul 23, 2015

So, with:

'webpack --output-library falcor --optimize-dedupe browser.js falcor-webpack.js'

I can get rid of the duplicate Model. Still have a duplicate Rx module, which results in the MergeObservable coming out of the mergeAll() here:

Not having a reduce operator, probably because it's added to the 'global' Rx by some other 'sub module.

@sdesai
Copy link
Contributor

sdesai commented Jul 23, 2015

I guess it's the rx.aggregates module which comes in and adds 'reduce', and so it's missing when the second copy of the rx core module is executed.

@sdesai
Copy link
Contributor

sdesai commented Jul 23, 2015

Yeah, that is it. If I manually alias them in the built file (replace webpack_require_(N) with whichever version of the Rx module Rx.aggregate augments), it works fine. Will see if there's a way to do this externally through official webpack config channels [ it seemed like resolve.alias was that ], or change the structure of the require pulling in rx.aggregate, and see if that helps.

@sdesai
Copy link
Contributor

sdesai commented Jul 23, 2015

In, falcor's entry point: falcor/lib/index.js

We have:

require('rx/dist/rx');
require('rx/dist/rx.aggregates');
require('rx/dist/rx.binding');

And in other places, we have:

require('rx/dist/rx');

The references to rx/dist/rx are all normalized to the same rx (core) Webpack module, which is fine.

However internally rx/dist/rx.aggregates and rx/dist/rx/binding are already bundled, with their own 'UMD' type handling, which require 'rx' in various forms [ amd, cjs, and global ]

Webpack takes the AMD path, and is using Rx's package.json browser entry to translate these rx dependencies into rx/dist/rx.all.js (as opposed to core), which is the 2nd or duplicate Rx module.

One is rx/dist/rx.js and the other is rx/dist/rx.all.js, and rx.all is the one which has the aggregate and binding methods (reduce etc). attached to the prototype, instead of the rx core module which everyone is using.

Since Webpack is taking the AMD path for rx/dist/rx.aggregates.js I don't think it's applying the resolve.alias hooks.

@sdesai
Copy link
Contributor

sdesai commented Jul 24, 2015

@memoryhole : This fixes it for me:

module.exports = {
  resolve: {
    alias: {
      'rx$': require.resolve('rx/dist/rx')
    }
  }
};

Can you give it a try?

The root cause is what I mention above.

@sdesai
Copy link
Contributor

sdesai commented Jul 24, 2015

Since this is an RxJS bug, rather than a Falcor one, planning to resolve this by:

  1. Adding the webpack.conf.js to the Falcor repo root (for anyone building Falcor using WebPack).
  2. Adding something to the README.md (or wherever we have build instructions), for people using Webpack to build projects which require('falcor').
  3. Submitting a bug (with potential fixes) for RxJS.

The cleaner permanent solution would be to have RxJS (or whichever Rx is bundled with Falcor) distributed as CJS modules, which we could require individually.

@sdesai
Copy link
Contributor

sdesai commented Jul 24, 2015

RxJS Bug, with repro: Reactive-Extensions/RxJS#832

@ThePrimeagen
Copy link
Contributor

This should be closed due to PR merged and behavior "fixed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants