Search code examples
node.jsreactjsbrowserify

Correct way to translate ES6 "import" to nodejs "require"


I'm tryng to reproduce the example reported here inside my project. The problem is that I'm using Browseryfy that seems to not support ES6 imports. So I thought of translate the third import of the example from:

import {Treebeard} from 'react-treebeard';

to

var Treebeard = require('react-treebeard').default;

But it still not works, and I get the following error:

Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined

I read of trying to switch to babelify but I will consider this option as very last. Thanks!


Solution

  • var Treebeard = require('react-treebeard').Treebeard;