Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] create-react-class does not work in AMD environment #9749

Closed
mondwan opened this issue May 23, 2017 · 4 comments
Closed

[BUG] create-react-class does not work in AMD environment #9749

mondwan opened this issue May 23, 2017 · 4 comments

Comments

@mondwan
Copy link

mondwan commented May 23, 2017

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

Unable to require such module. This bug seems similar to #8301. React uses without proper require calls .

// Copied from https://unpkg.com/create-react-class@15.5.3/create-react-class.js
.....
var factory = require('./factory');

// Hack to grab NoopUpdateQueue from isomorphic React
var ReactNoopUpdateQueue = new React.Component().updater;
....

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/84v837e9/).

Here is a jsfiddle.

https://jsfiddle.net/w5xjbgcy/12/

Errors from jsfiddle

Uncaught TypeError: React.Component is not a constructor
    at Object.2../factory (create-react-class.js:764)
    at s (create-react-class.js:22)
    at e (create-react-class.js:22)
    at create-react-class.js:22
    at Object.execCb (require.js:1693)
    at Module.check (require.js:881)
    at Module.enable (require.js:1173)
    at Module.init (require.js:786)
    at callGetModule (require.js:1200)
    at Object.completeLoad (require.js:1587)

What is the expected behavior?

Able to load create-react-class without problem

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

  • React 15.5.4
  • create-react-class 15.5.3
@mondwan
Copy link
Author

mondwan commented May 23, 2017

Although below solution is not tried at the exactly same environment as jsfiddle posted, just leave it as a reference.

I can fix the error by adding require('react') at create-react-class.js as following diff

--- node_modules/create-react-class/create-react-class.js	2017-05-10 07:57:00.000000000 +0800
+++ create-react-class.js	2017-05-23 14:44:30.456446125 +0800
@@ -757,10 +757,11 @@
  */
 
 'use strict';
 
 var factory = require('./factory');
+var React = require('react');
 
 // Hack to grab NoopUpdateQueue from isomorphic React
 var ReactNoopUpdateQueue = new React.Component().updater;

@jochenberger
Copy link

#9689

@mondwan
Copy link
Author

mondwan commented May 23, 2017 via email

@mondwan mondwan closed this as completed May 24, 2017
@gaearon
Copy link
Collaborator

gaearon commented Jun 13, 2017

This should be fixed with create-react-class@15.6.0-rc.0. Please verify (I plan to publish the final 15.6.0 version of it tomorrow).

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

No branches or pull requests

3 participants