babel / babelify

Browserify transform for Babel
MIT License
1.68k stars 114 forks source link

TypeError: React.Dom is not a function #180

Closed artaommahe closed 8 years ago

artaommahe commented 8 years ago

After replacing reactify with babelify have this eror in console for all jsx files

TypeError: React.Dom is not a function

this is render functions in bundle

return React.Dom(
  'div',
  ...

sample original

/** @jsx React.Dom */
'use strict';

var React = require('react');
var ReactDOM = require('react-dom');
...
  render: function() {

    ...

    return (
      <div className="list-wrapper">
        {items}
      </div>
    );
  }

package.json

"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babelify": "^7.2.0",
"react": "~0.14.6",
"react-dom": "^0.14.6",

gulpfile

bundler.transform(babelify, {
  extensions: ['.jsx'],
  presets: ['es2015', 'react']
});

As i understand there must be return React.Dom.div(...) instead of return React.Dom('div', ...)

loganfsmyth commented 8 years ago

It looks like you're using an older version of React, correct? React.Dom.div is 0.12, but the react preset assumes you are using 0.14.

For 0.12, what you want is to install/enable babel-plugin-transform-react-jsx-compat.

bundler.transform(babelify, {
  extensions: ['.jsx'],
  presets: ['es2015', 'react'],
  plugins: ['transform-react-jsx-compat']
});
artaommahe commented 8 years ago

@loganfsmyth oh, sorry, added react version to first post, it's 0.14.6

loganfsmyth commented 8 years ago

Ah okay, I assumed you were on 0.12 since you said

As i understand there must be return React.Dom.div(...) instead of return React.Dom('div', ...)

For 0.14 then, you issue is just that you have /** @jsx React.Dom */ in there, which is what is telling it to do the weird behavior it is doing now. Delete the pragma and it'll do React.createElement('div', which is the way to do it in 0.14.

artaommahe commented 8 years ago

@loganfsmyth yep, it is the solution, thx ;)