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

react\react.js does not export default #10

Closed
egoist opened this issue Dec 15, 2015 · 11 comments
Closed

react\react.js does not export default #10

egoist opened this issue Dec 15, 2015 · 11 comments

Comments

@egoist
Copy link

egoist commented Dec 15, 2015

I have React installed in node_modules and import it in ./src/main.js, with such configs:

{
  entry: './src/main',
  dest: './build/bundle.rollup.js',
    plugins: [
      npm({
        main: true
      }),
      commonjs({
        include: 'node_modules/**'
      }),
      babel({
        exclude: 'node_modules/**'
      })
  ],
  format: 'iife'
}

But it ran into some issue:

Module *\react\react.js does not export default (imported by *\src\main.js)

Without rollup-plugin-npm it works but sure it does not include React in the Rollup bundle.

@Rich-Harris
Copy link
Contributor

That's odd. It works for me in this simple example: https://gist.github.com/Rich-Harris/cd0c293f5263b2450412. (Clone it, npm i, then npm run build – it will open a test page that logs the value of React.) Can you share your repo?

Strictly speaking, your code should probably say

import * as React from 'react';

rather than

import React from 'react';

since React itself is just a namespace.

@egoist
Copy link
Author

egoist commented Dec 18, 2015

thx, this should work.

@egoist egoist closed this as completed Dec 18, 2015
@atombender
Copy link

Getting the same error here. And using import * as React shouldn't really be necessary. We're investigating migrating from Browserify, which is quite happy to import React like this. In particular, we use the idiom:

import React, {PropTypes} from 'react';

@atombender
Copy link

I'm wondering if this related:

Module /tmp/foo/node_modules/react-router/lib/index.js does not export Route (imported by /tmp/foo/app/components/Root.react.jsx)

That particular module uses this way of exporting stuff. Works with Browserify, though.

@atombender
Copy link

Looks like using rollbar-plugin-commonjs instead of this package solves these issues.

@dtothefp
Copy link

dtothefp commented Mar 9, 2016

@atombender @Rich-Harris I'm confused about this error, I get it when using the babel plugin along with the node-resolve and commonjs rollup plugins.

If I build my code allowing all node_modules includeed in the commonjs plugin, I get errors with babel-runtime helpers.

Uncaught TypeError: _createClass is not a function

because it is trying to call a ['default'] key var _createClass = require$$9$1['default'];, where when it is assigned to the variable require$$9$1 it has already accessed the function from the default key

//this ternary check is true
var require$$9$1 = (createClass && typeof createClass === 'object' && 'default' in createClass ? createClass['default'] : createClass);

When I exclude the babel-runtime helpers from the commonjs plugin I get a compilation error

[Error: Module /Users/davidfox-powell/dev/mobile-donate/node_modules/babel-runtime/helpers/interop-require-wildcard.js does not export default

https://github.com/rollup/rollup/blob/157ba12cedf62f8833bbcbb90ba55ca4f18631fe/src/Module.js#L620

I have no idea why this is happening, and am curious if it is a bug or I am just not including/excluding properly?

@Hikariii
Copy link

Having the same kind of issue:

In my rollup config I have the following:

{
    globals: { "underscore": "require('underscore')"},
    external: ['underscore']
}

My iife bundle function is called like:

(function (_) {
'use strict';

var ___default = _['default'];

///all the code

}(require('underscore')));

But inside the code ___default is undefined.
Can't I force rollupJS to just assign underscore like this:

_= 'default' in _? _['default'] : _;

@Hikariii
Copy link

Hikariii commented Jan 27, 2017

Just added interop: false to the rollup config and recompiled.
This removed the var ___default = _['default']; assignment,
but still underscore is referenced as ___default

var i = ___default.findIndex( must be _.findIndex

Any tips on how to do this?

@dtothefp
Copy link

dtothefp commented Jan 27, 2017

hey @Hikariii not sure about underscore, but to get lodash working I used common-js plugin. I'm guessing that you need common-js plugin to tell node-resolve that your node-modules/underscore is not es6, so therefore would not be imoprted/requireed with a default key. Maybe this helps ¯\_(ツ)_/¯

    nodeResolve({
      extensions: ['.js'],
      main: true,
      browser: true,
      preferBuiltins: false
    }),
    commonjs({
      namedExports: {
        lodash: [
          'assign',
          'keys',
          'max',
          'set',
          'values'
        ]
      },
      include: [
        'node_modules/**/*.js'
      ],
      exclude: [
        es6Glob
      ]
    }),

@wan54
Copy link

wan54 commented Jul 11, 2018

Any updates on this? Got the same issue with React.

var React__default = React['default'];
// React['default'] is undefined

@wan54
Copy link

wan54 commented Jul 13, 2018

We were using 0.56.5. Upgraded to 0.62.0 fixed the issue.

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