redux-saga: Bundling with Rollup fails due to missing export

Hello,

i’m trying to bundle my project using redux-saga and stumbled upon an issue.

using the node-resolve plugin for rollup and the { jsnext: true } option gives me the following error:

'CHANNEL_END' is not exported by '$PATH_TO_PROJECT$\node_modules\redux-saga\es\internal\io.js' (imported by '$PATH_TO_PROJECT$\node_modules\redux-saga\es\utils.js') Error: 'CHANNEL_END' is not exported by '$PATH_TO_PROJECT$\node_modules\redux-saga\es\internal\io.js' (imported by '$PATH_TO_PROJECT$\node_modules\redux-saga\es\utils.js') at Module.traceExport ($PATH_TO_PROJECT$\node_modules\rollup\src\Module.js:376:17) ...

Looking at the es/internal/io.js module there is no export for this but the es/utils.js re-exports this constant.

es/utils.js export { CHANNEL_END, asEffect } from './internal/io';

Setting the { jsnext: false } option solves the issue as a workaround but also disables all other es6 imports.

Did I miss something or is this a small bug?

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 48 (37 by maintainers)

Commits related to this issue

Most upvoted comments

thanks to @Ephys I’ll release a patch version today which should fix this problem entirely and fixes/hacks like:

  • aliasing
  • @nktssh 's redux-saga-effects package
  • importing effects from redux-saga
  • etc

should become obsolete 🎉

@zech @ok111net - please check out the new release and let me know

The solution of splitting the lib into separate modules and have them required by each other if neccessary - monorepo style - seems the most viable.

@zech how would it mix up es6 and es5 code during the build? what do you mean?

bug with wrong import doesn’t affect webpack 1 and webpack 2 users - use both of them on different project, all as expected.

the main problem is to have 2 entry points while all build systems expect only 1 main file. At least two approaches coming to my mind:

  • make 1 entry point
  • split redux-saga package into two: redux-saga-core and redux-saga-effects (naming is just example)

Ok, I think I know why this happens, but aint sure how it should be solved.

  1. redux-saga/effects is interpreted as node_module, so its traversing the directory tree and searches for that using this https://github.com/substack/node-resolve/blob/7f0ce871b6d2b5cb2082b04cd72ddd4055cb7a05/lib/async.js#L172
  2. its checking always if the found thing is a dir or file and act accordingly
  3. it finds this https://github.com/yelouafi/redux-saga/blob/250e722419f9fcaade729c51aaf5d97a3de2b16a/effects.js and loads accordingly which in your case unfortunately points at the wrong file (from the lib) folder

In case of redux-saga itself it finds a correct directory and rollup later concatanates path with jsnext:main option. But its not working with effects.js for quite obvious reasons.

Ill try to reach out to rollup users so it can be handled in a better way.

@yelouafi I’ve always wondered about dir structure in the repo, could you elaborate a little bit more on it? Ive always assumed that webpack when importing redux-saga/effects is reaching for ./lib/effects.js but it might seem (didnt check it though) that its reaching for ./effects.js and this only acts as a ‘proxy’ to the beforementioned file. Its kinda non obvious at first and Im wondering if maybe it could be somehow organised better as this ‘proxy’ seems a little bit hacky