Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Can't import named exports - (Affecting react, react-dom among others) #185

Closed
ajaska opened this issue Mar 21, 2017 · 12 comments
Closed

Can't import named exports - (Affecting react, react-dom among others) #185

ajaska opened this issue Mar 21, 2017 · 12 comments
Labels

Comments

@ajaska
Copy link

ajaska commented Mar 21, 2017

Hi, I'm getting problems on rollup 0.41.6 + rollup-plugin-commonjs 8.0.2 with importing named exports from react, react-dom, react-dates.

I'm pretty sure this worked before, so I made this minimal example which causes issues (and as far as I am able to tell, rollup-plugin-commonjs should be able to handle). It works fine just babelifying it.

I'm invoking rollup -c, here is rollup.config.js:

import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

const options = {
  entry: 'index.js',
  dest: 'output.js',
  format: 'umd',
  plugins: [
    nodeResolve(),
    commonjs(),
  ],
};

export default options;

Here's my index.js

import { MyFunction } from 'fake-repro-package';

console.log(MyFunction());

And here's node_modules/fake-repro-package/index.js:

module.exports = {
  MyFunction: function() { return 8; },
};

This results in the error:

🚨   'MyFunction' is not exported by node_modules/fake-repro-package/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
index.js (1:9)
1: import { MyFunction } from 'fake-repro-package';
            ^
2: 
3: console.log(MyFunction());
@ajaska
Copy link
Author

ajaska commented Mar 21, 2017

FWIW, adding them to the namedExports in the config does appear to work -- but I don't think I should have to be doing that for such a trivial case (which the docs say should work :) ).

@ajaska
Copy link
Author

ajaska commented Mar 22, 2017

I did a quick check, and with [email protected],

Versions of rollup-plugin-commonjs through 4.1.0 work with this example, versions 5.0.0+ require the namedExports workaround. A quick visual inspection suggests #186 may be related, and #115 looks very much related -- even noting the fix of downgrading to 4.1.0

@ajaska
Copy link
Author

ajaska commented Apr 4, 2017

Ah, I hate to be intrusive and tag you directly, I'm sure you're quite busy, but @Rich-Harris any chance you could take a look at this?

This is a clear regression (with repro!) and I'm not going crazy, right?

@flying-sheep
Copy link

@kirbdee
Copy link

kirbdee commented Jun 1, 2017

You need to explicitly name "MyFunction" in the namedExports config.

Another alternative (which is interestingly observed and I'm not sure if this is intended):

import {default as fakeRepo} from 'fake-repo-package'; //some commonJS with module.exports

fakeRepo.MyFunction() //this will be available w/o any nameExports

@ajaska
Copy link
Author

ajaska commented Jun 2, 2017

Right, those are both workarounds, that should function (but adding tons of namedExports can get annoying fast).

It used to work without needing namedExports. I've switched back to webpack for now :)

@fregante fregante added the bug label Jun 22, 2017
@kopax
Copy link

kopax commented Sep 30, 2017

I think I might have the same error with redux and redux-form, I've posted here en SO. Any workaround ?

@rtsao
Copy link

rtsao commented Nov 9, 2017

Experiencing the same issue with enzyme-adapter-react-16 (as well as react, etc.)

@kopax
Copy link

kopax commented Nov 9, 2017

I've managed to solved many cases of named exports by using modulesOnly: true

@geoyws
Copy link

geoyws commented May 13, 2018

@kopax modulesOnly: true solved my problem. Thanks man.

@onlywei
Copy link

onlywei commented Mar 20, 2019

@kopax @geoyws what is "modulesOnly"? I don't see that as an option of this plugin.

@shellscape
Copy link
Contributor

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. 🍺

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

No branches or pull requests

9 participants