-
Notifications
You must be signed in to change notification settings - Fork 126
babel-converted module with default comes out wrong #29
Comments
Please provide the steps to reproduce! We can't help you otherwise. |
here;
|
there’s more. e.g. this file converts using var _interopRequire = require('babel-runtime/helpers/interop-require')['default']; which rollup can’t handle as well |
Have spent some time wrestling with this issue. It's tricky – the problem is that var foo = require('foo'); is converted to import foo from 'foo'; but it doesn't mean that in the context of a CommonJS module that was compiled from an ES6 module with Babel ( To be honest, I'm not sure it's the right problem to solve. It's insane to keep converting modules back and forth between different formats – you add cruft with each conversion. I think it makes a lot more sense to look at how we can use Redux directly as an ES6 module. Here's how. We can't simply do this... import { combineReducers } from 'redux/src/index.js'; ...because Redux has a Babel 5 config that's incompatible with Babel 6 (assuming we're using Babel 6 to bundle our own source code), but we can use Rollup to create our own build of Redux. Bonus: you get a smaller (and tree-shakeable) version of Redux! Long term, the best solution is to encourage library authors to distribute ES6 modules using Let me know if you have any questions about that setup. |
hey, check out reduxjs/react-redux#256. this is something we can teach people to do if they want to support
well, sadly that means that i basically have to
|
You can add react-big-calendar as another package broken by this issue.
Is the error. Which occurs because src/localizers/moment.js imports src/formats.js and presumably rollup can't set I don't think There is certainly going to be a lot of pushback on requests to add Which presents a chicken and egg issue. As long as the rollup userbase is small many package maintainers aren't going to want to support |
meh, that’s a common misconception caused by the second hard thing (naming things). it’s not the source unless you only use module syntax and elsewise only node-compatible code. for packages requiring more babel transforms it’s actually a second, differently-compiled bundle that needs to be published feel free to read all of reduxjs/react-redux#256 to evaluate the actual amount of pushback this can create.
webpack 2 will also support es2015 module syntax; no idea about jsnext:main |
@dantman I want to clarify that We recommend library authors to bundle their libraries (excluding external dependencies) into both CommonJS |
yeah, and people are already pushing back against the very idea of doing that. |
besides i don’t like how node’s
then |
Sorry if I may just intrude into this conversation, without having read all of it. While I would love to be able to consume a library via The reason is namespace re-exports. Consider this example. The library re-exports a namespace import, and as long as those are still in separate files, rollup can deal with it just fine and eliminate the things from the namespace export that I don’t use. When you pre-bundle that library for And just fyi, my specific usecase is this: |
Just playing around with this, I’m actually surprised that rollup can deal with deeply nested namespace re-exports, like here. That’s 4 files deep. I stopped trying more, maybe it could deal with a potentially arbitrary depth. |
@Swatinem I understand your concern with namespaces. I believe that the ease-of-use that comes with exporting bundled & transpiled code via
Indeed it can. 😃 |
which involves an ad-hoc-update and looking up and reusing redux’ .babelrc if we want to compete with other tools, this using redux properly needs to be one line of config total, not spread over a dozen lines in multiple files. another problem is libs relying on babel’s liberal interpretation of how commonjs modules should work when imported via ES6, i.e. try importing code containing this line and it’ll fail since React is interpreted to only |
@Victorystick you can add Facebook's Any solutions or are we just out of luck if code is pre-compiled? rollup/rollup-plugin-babel#13 (comment) |
Seems related to heroku/react-refetch#114 react-refetch publishes only the compiled edition that is compiled with webpack and babel Reading the comments above, could my work with https://github.com/bevry/editions help this? |
@balupton unfortunately the only solution I found was to marke Parse as external and then load it via CDN or other method. Unfortunately in the end there were too many gotchas like this with roll up when applying to a medium/large scale app and I reverted back to webpack. Also you notice none of the maintainers seems to respond to github issues reliably so it makes it hard to figure out these small blocking issues |
This is a blocking bug for me using rollup. It seems much more intuitive and easy to use than webpack, but I really need redux. |
Same here. I was already using rollup for other projects. But today I wanted to start a small react/redux project and was wondering rollup is not (yet) supporting redux. |
Why was this closed? Was something done to resolve the issues people were encountering with using Redux with Rollup? |
@AlexGalays Redux has |
EDIT: a public trace of sleep deprivation. |
@rgrymam I guess it's because redux doesn't have connect util. It's just wrong package. You should use react-redux for that. |
... and I miss something obvious 😅, I need some sleep. Thanks and sorry. |
when trying to bundle redux, i get
TypeError: _createStore.ActionTypes is undefined
the code in
createStore.js
is basically:which gets wrapped into
createStore$1
followed byand the failing code is
var initialState = reducer(undefined, { type: _createStore.ActionTypes.INIT });
hmm, obviously
_createStore
gets assigned to thefunction createStore
directly.the failing line should convert to contain
createStore$1.ActionTypes.INIT
isn’t there an effort to handle
__esModule
properly?The text was updated successfully, but these errors were encountered: