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

Webpack-bundled output duplicates history/es/* and history/* imports #5576

Closed
mattdistefano opened this issue Sep 30, 2017 · 5 comments
Closed

Comments

@mattdistefano
Copy link

Version

4.2.0 (w/ webpack 3.6.0)

Test Case

https://github.com/mattdistefano/react-router-repro

Steps to reproduce

See repo above - very basic webpack config, but compiled output in dist/index.js duplicates much of the history package (search for var createBrowserHistory to confirm) by including both the esm files from node_modules/history/es and CJS equivalents from node_modules/history.

It seems like the deep-import react-router does from history - import createHistory from 'history/createBrowserHistory'; - causes webpack to dup the imported code. Doing a named import instead - import { createBrowserHistory as createHistory } from 'history'; - seems to work better (though it looks like history doesn't re-export everything RR needs ATM).

I'm not sure if this is a webpack bug or an RR but figured I'd log it here first.

Expected Behavior

Should get just the ESM files in the bundle.

Actual Behavior

See above.

@pshrmn
Copy link
Contributor

pshrmn commented Sep 30, 2017

Possibly related to #5095.

@nikarh
Copy link

nikarh commented Oct 20, 2017

As far as I can tell, react-router imports history in two ways, first one:

import { createLocation, locationsAreEqual } from 'history';

Since history module has a "module": "es/index.js" key in package.json webpack resolves it to history/es/index.js.

The second is

import createHistory from 'history/createMemoryHistory';

According to the modules proposal, history package doesn't have a "modules.root" key in package.json, thus webpack doesn't translate this import to history/es/createMemoryHistory.

I think the most obvious solution here would be a PR to a history project with modules.root,
but for now you can alias specific imports used by react-router in webpack config:

resolve: {
    alias: {
      'history/createMemoryHistory':
        path.resolve(__dirname, 'node_modules/history/es/createMemoryHistory'),
      'history/createHashHistory':
        path.resolve(__dirname, 'node_modules/history/es/createHashHistory'),
      'history/createBrowserHistory':
        path.resolve(__dirname, 'node_modules/history/es/createBrowserHistory'),
      'history/PathUtils':
        path.resolve(__dirname, 'node_modules/history/es/PathUtils')
    }
}

timdorr pushed a commit that referenced this issue Nov 13, 2017
* Use named import of 'history' module.

* Coding style fixes.
@DullReferenceException
Copy link

I see the fix was merged 3 months ago; when can we expect a new version with this fix to be published?

@dawsonc623
Copy link

I am having sort of the flip-side to this issue. It seems React Router wants to import from history/es/*, but the package sent only contains history/*. Not sure if this is related or belongs in its own issue.

@KyleAMathews
Copy link
Contributor

👍 to a new release

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
jeresig pushed a commit to Khan/react-router that referenced this issue Aug 29, 2018
…n#5589)

* Use named import of 'history' module.

* Coding style fixes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants